|
-
Jul 11th, 2000, 07:38 AM
#1
Thread Starter
Addicted Member
hi there anyone know how to check if a directory is on a drive. I am looking for "C:\bakup" and if it is no found the create the directory?
Rohan West
-
Jul 11th, 2000, 07:48 AM
#2
Member
I don't know if there a possibility to test that. But try to create another directory which has the same name. If the MkDir function return an error (Err 58: already exist), you've got you're answer ! 
PS: I've just see that DirExists does what you want. Thanks to HeSaidJoe
[Edited by (B2F)Tom on 07-11-2000 at 08:52 AM]
-
Jul 11th, 2000, 07:49 AM
#3
Frenzied Member
here you are:
Code:
Private Sub Command1_Click()
If Dir("C:\bakup", vbDirectory) = "" Then
MkDir "C:\bakup"
End If
End Sub
-
Jul 11th, 2000, 07:56 AM
#4
_______
<?>
look at your previous post...
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Jul 11th, 2000, 11:09 AM
#5
Fanatic Member
Using API's
Code:
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" _
(ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
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
Public Const INVALID_HANDLE_VALUE = -1
Public Const FILE_ATTRIBUTE_DIRECTORY = &H10
Public 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
Public 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
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
|