FileType ( file$ )
Parameters
| file$ - path to check |
Description
|
Returns whether a path is a file, a directory, or nothing at all. The possible return values are: 0 : nothing exists at that path 1 : it is a file 2 : it is a directory This is the standard "does it exist?" check before reading a save file, and the way to tell files from folders while walking a directory with ReadDir and NextFile$. It is also how you verify the silent file commands (CreateDir, DeleteFile, CopyFile and friends) actually did their job. See also: FileSize, ReadDir, NextFile, DeleteFile. |
Example
; FileType Example ; ---------------- ; Create a demo file and a demo folder to inspect file=WriteFile("demo_filetype.txt") WriteLine file,"hello" CloseFile file CreateDir "demo_folder" ; FileType returns 1 for a file, 2 for a directory, 0 for not found Print "demo_filetype.txt : "+FileType("demo_filetype.txt")+" (1 = file exists)" Print "demo_folder : "+FileType("demo_folder")+" (2 = directory)" Print "no_such_file.txt : "+FileType("no_such_file.txt")+" (0 = not found)" ; Clean up the demo file and folder DeleteFile "demo_filetype.txt" DeleteDir "demo_folder" Print "" Print "Cleaned up demo file and folder" Print "" Print "Press any key to close the example" WaitKey End
Index