How to check if a directory exists?

BlitzPlus Forums/BlitzPlus Beginners Area/How to check if a directory exists?

Kirkkaf(Posted 2012) [#1]
Hi everyone,

How can I check if a directory exists or not?

Thanks.

Last edited 2012


Zethrax(Posted 2012) [#2]
Not too sure if this applies to BlitzPlus, but in Blitz3d you would use FileType and check for a return value of 2.

You can also use ReadDir and NextFile to sequence through all the files and directories in a directory.

eg. (Blitz3D code)

; ReadDir/NextFile$/CloseDir example 

; Define what folder to start with ... 
folder$="C:" 

; Open up the directory, and assign the handle to myDir 
myDir=ReadDir(folder$) 

; Let's loop forever until we run out of files/folders to list! 
Repeat 
; Assign the next entry in the folder to file$ 
file$=NextFile$(myDir) 

; If there isn't another one, let's exit this loop 
If file$="" Then Exit 

; Use FileType to determine if it is a folder (value 2) or a file and print results 
If FileType(folder$+"\"+file$) = 2 Then 
Print "Folder:" + file$ 
Else 
Print "File:" + file$ 
End If 
Forever 

; Properly close the open folder 
CloseDir myDir 

; We're done! 
Print "Done listing files!"  



Matty(Posted 2012) [#3]
Yep same should work in blitzplus as it does in blitz3d.