发表评论(0)作者:不详Karl Moore, 平台:VB6.0+Win98, 阅读:9250, 日期:2001-06-06
Creating Nested Directories
Need to check for the existence of a nested directory? And if it isn注释:t there, need to create it?
If you注释:re already shuddering at the prospect of complex checking algorithms, never fear - here to help is yet another handy copy-and-paste code snippet!
This one works by calling a function in the IMAGEHLP DLL... and if the directory specified doesn注释:t exist, it creates it for you. And you can go down as many levels as you want - this function handles nested directories with ease.
To use this code, call CreatePath, passing in the path to create. The function returns True if successful.
Usage
x = CreatePath("c:\program files\new app\database\references")Code
Declare Function MakeSureDirectoryPathExists Lib _
"IMAGEHLP.DLL" (ByVal DirPath As String) As Long
Public Function CreatePath(NewPath) As Boolean
注释:Add a trailing slash if none
If Right(NewPath, 1) <> "\" Then
NewPath = NewPath & "\"
End If
注释:Call API
If MakeSureDirectoryPathExists(NewPath) <> 0 Then
注释:No errors, return True
CreatePath = True
End If
End Function
Tip by Karl Moore
Need to check for the existence of a nested directory? And if it isn注释:t there, need to create it?
If you注释:re already shuddering at the prospect of complex checking algorithms, never fear - here to help is yet another handy copy-and-paste code snippet!
This one works by calling a function in the IMAGEHLP DLL... and if the directory specified doesn注释:t exist, it creates it for you. And you can go down as many levels as you want - this function handles nested directories with ease.
To use this code, call CreatePath, passing in the path to create. The function returns True if successful.
Usage
x = CreatePath("c:\program files\new app\database\references")Code
Declare Function MakeSureDirectoryPathExists Lib _
"IMAGEHLP.DLL" (ByVal DirPath As String) As Long
Public Function CreatePath(NewPath) As Boolean
注释:Add a trailing slash if none
If Right(NewPath, 1) <> "\" Then
NewPath = NewPath & "\"
End If
注释:Call API
If MakeSureDirectoryPathExists(NewPath) <> 0 Then
注释:No errors, return True
CreatePath = True
End If
End Function
Tip by Karl Moore