| dir$ - path and name of the directory to create |
|
Creates a new directory. Typical game use: making a "saves" or "screenshots" folder the first time the game runs. The path can be absolute or relative to the current directory, and should not end with a trailing slash. Only one level is created at a time - the parent folder must already exist, so to build "data\saves\slots" create each level in turn. CreateDir reports nothing if it fails (for example when the parent is missing or the name is already taken), so verify with FileType, which returns 2 once the directory exists. See also: DeleteDir, FileType, ChangeDir. |
; CreateDir Example
; -----------------
; Create a new folder in the current directory (no trailing slash)
CreateDir "demo_folder"
; CreateDir returns nothing - verify with FileType (2 = directory)
If FileType("demo_folder")=2 Then
Print "demo_folder created successfully"
Else
Print "demo_folder could not be created"
EndIf
; A freshly created folder can hold files straight away
file=WriteFile("demo_folder\save.txt")
WriteLine file,"saved!"
CloseFile file
Print "Wrote demo_folder\save.txt"
; Clean up (a folder must be empty before DeleteDir)
DeleteFile "demo_folder\save.txt"
DeleteDir "demo_folder"
Print "Cleaned up demo_folder"
Print ""
Print "Press any key to close the example"
WaitKey
End