FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

DISK I/O

Create a folder


newFolderNum% = FOLDER( "New Folder Name", VolRefNum% )

John


' This program creates a new folder in the application's (or source code's) folder.
' If folderName$ already exists as a folder then use it instead of creating a new one.
' If folderName$ exists as a file then attempt to create a folder with a number added on.

' appVolRefNum% --- Application's folder reference number
' vRefNum% --- Reference number of folder to open (folderName$)
' folderName$ --- name of folder to create

folderName$ = "Output" ' name of new folder to be created
xfolderName$ = folderName$
appVolRefNum% = SYSTEM(_aplVol) ' get vol ref of Application

ref% = FOLDER("", appVolRefNum%) ' make our app folder the current folder
vRefNum% = FOLDER(folderName$, 0) ' look for folderName$ in current folder
LONG IF vRefNum% = 0 ' folder doesn't exist in current folder
  vRefNum% = FOLDER(folderName$, SYSTEM(_aplVol)) ' create new folder
END IF

' if vRefNum% = 0 then folderName$ probably exists as a file so attempt
' to create another folder with a number added on. If we can't create it after
' 10 attempts then exit with error message.
X = 0
WHILE vRefNum% = 0 AND X < 10
  X = X + 1
  xfolderName$ = folderName$ + STR$(X)
  LONG IF vRefNum% = 0
    vRefNum% = FOLDER(xfolderName$, SYSTEM(_aplVol))' create new folder
  END IF
WEND
LONG IF vRefNum% = 0
  err$ = "The folder " + CHR$(34) + folderName$ + CHR$(34) + " could not be created."
  CALL PARAMTEXT (err$, "", "", "")
  but% = FN STOPALERT(129,0)
XELSE
  folderName$ = xfolderName$
' open a file and do whatever.
' code below is just to show that we are working with the correct folder.
  DEF OPEN "TEXTttxt"
  OPEN "O", #1, "Test File",, vRefNum%
  PRINT #1, "The folder is named ";
  PRINT #1, folderName$
  CLOSE #1
END IF

Al Staffieri Jr.