|
-
Oct 22nd, 2000, 10:52 AM
#1
Thread Starter
Frenzied Member
I currently use this code to see if a file exists:
Public Function FileExist(sData As String) As Boolean
On Error Resume Next
If sData <> "" Then
File = Len(Dir$(sData))
If Err Or File = 0 Then
FileExist = False
Else
FileExist = True
End If
End If
End Function
but if i want to use it to see if a directory exists it never works, is there a proper way to do this ?
-
Oct 22nd, 2000, 10:59 AM
#2
Frenzied Member
Code:
Private Const MAX_PATH = 260
Private Const INVALID_HANDLE_VALUE = -1
Private Const FILE_ATTRIBUTE_DIRECTORY = &H10
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
Private Declare Function FindFirstFile Lib "kernel32" _
Alias "FindFirstFileA" _
(ByVal lpFileName As String, _
lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindNextFile Lib "kernel32" _
Alias "FindNextFileA" _
(ByVal hFindFile As Long, _
lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindClose Lib "kernel32" _
(ByVal hFindFile As Long) As Long
Private Function FolderExists(sFolder As String) As Boolean
Dim hFile As Long
Dim WFD As WIN32_FIND_DATA
'remove training slash before verifying
sFolder = UnQualifyPath(sFolder)
'call the API pasing the folder
hFile = FindFirstFile(sFolder, WFD)
'if a valid file handle was returned,
'and the directory attribute is set
'the folder exists
FolderExists = (hFile <> INVALID_HANDLE_VALUE) And _
(WFD.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY)
'clean up
Call FindClose(hFile)
End Function
Private Function UnQualifyPath(ByVal sFolder As String) As String
'trim and remove any trailing slash
sFolder = Trim$(sFolder)
If Right$(sFolder, 1) = "\" Then
UnQualifyPath = Left$(sFolder, Len(sFolder) - 1)
Else: UnQualifyPath = sFolder
End If
End Function
-
Oct 22nd, 2000, 11:02 AM
#3
Junior Member
If You Want To Make The Dir is Its No There
on error goto matt
'Do What Ever You Want With the Dir
matt:
mkdir ("c:\Yourfolder")
-
Oct 22nd, 2000, 11:25 AM
#4
Thread Starter
Frenzied Member
-
Oct 22nd, 2000, 11:48 AM
#5
transcendental analytic
Shoudn't be that hard, dir's working as it should:
cbool(len(dir("C:\windows",vbDirectory )))
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Oct 22nd, 2000, 12:53 PM
#6
Code:
If Dir("C:\Windows", vbDirectory) <> "" Then MsgBox ("Dir exists")
-
Oct 22nd, 2000, 02:49 PM
#7
Thread Starter
Frenzied Member
Thats what i was using except that it never worked , the code i have now does though.
-
Oct 22nd, 2000, 04:24 PM
#8
transcendental analytic
should work! Maybe you put an extra "\" after the path?
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Oct 23rd, 2000, 02:28 PM
#9
Thread Starter
Frenzied Member
no silly me just did not put 'vbDirectory'
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|