38 lines
1.1 KiB
Text
38 lines
1.1 KiB
Text
' FB 1.05.0 Win64
|
|
|
|
' Enable FileExists() function to be used
|
|
#include "file.bi"
|
|
|
|
' Use Win32 function to check if directory exists on Windows 10
|
|
Declare Function GetFileAttributes Lib "kernel32.dll" Alias "GetFileAttributesA" _
|
|
(ByVal lpFileName As ZString Ptr) As ULong
|
|
|
|
Const InvalidFileAttributes As ULong = -1UL
|
|
Const FileAttributeDirectory As ULong = &H10UL
|
|
|
|
Sub CheckFileExists(ByRef filePath As String)
|
|
If FileExists(filePath) Then
|
|
Print "'"; filePath; "' exists"
|
|
Else
|
|
Print "'"; filePath; "' does not exist"
|
|
End If
|
|
End Sub
|
|
|
|
Sub CheckDirectoryExists(ByVal dirPath As ZString Ptr)
|
|
Dim attrib As ULong = GetFileAttributes(dirPath)
|
|
Dim dirExists As ULong = attrib <> InvalidFileAttributes AndAlso (attrib And FileAttributeDirectory) <> 0
|
|
If dirExists Then
|
|
Print "'"; *dirPath; "' exists"
|
|
Else
|
|
Print "'"; *dirPath; "' does not exist"
|
|
End If
|
|
End Sub
|
|
|
|
CheckFileExists(CurDir + "\input.txt")
|
|
Dim dirPath As String = CurDir + "\docs"
|
|
CheckDirectoryExists(StrPtr(dirPath))
|
|
CheckFileExists("c:\input.txt")
|
|
CheckDirectoryExists(StrPtr("c:\docs"))
|
|
Print
|
|
Print "Press any key to quit the program"
|
|
Sleep
|