here's my problem
i want to move the file
"c:\test\myfolder\myfile.txt" to "d:\test\myfolder\myfile.txt"
but the folder "d:\test\myfolder\" doesn't exist...
Printable View
here's my problem
i want to move the file
"c:\test\myfolder\myfile.txt" to "d:\test\myfolder\myfile.txt"
but the folder "d:\test\myfolder\" doesn't exist...
Use this API before your copyThe API will create the folder if it doesn't already exist, and do nothing if it does.vb Code:
Option Explicit Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" _ (ByVal lpPath As String) As Long Private Sub cmdCopyFiles_Click MakeSureDirectoryPathExists "d:\test\myfolder\" FileCopy "c:\test\myfolder\myfile.txt", "d:\test\myfolder\myfile.txt" End Sub
wow cool!!! thanks very much and very quick reply!!!
edit:
it doesn't seem to work... the missing folders are not created.... :(
edit2:
ok just saw ur post below :) it works great with "\" at the end !!! thanks again!
No problem.
One last comment. Even though I've used that API about a zillion times I still get caught in a "gotcha" with it. If you don't include the last, trailing, backslash, the API won't work.
In other words "d:\test\myfolder\" will result in the folder being created, if it doesn't exist, or ignored if it does. However, "d:\test\myfolder" will result in the folder NOT being created, but, you won't know it until your copy blows up. Without the trailing backslash the folder won't be created, and you won't receive an error message.
Also, If you consider this resolved, would you please pull down the Thread Tools menu and click the Mark Thread Resolved menu item? That will let everyone know that you have your answer.
Thank you. :)
I have used the code Hack suggested here...
but it doesn't create a new folder when the tvwCode.SelectedItem folder does not exist.vb Code:
MakeSureDirectoryPathExists App.Path & "\" & tvwCode.SelectedItem
Anybody see why?
Thanks
Try it like this:
vb Code:
MakeSureDirectoryPathExists App.Path & "\" & tvwCode.SelectedItem & "\"
....Quote:
Originally Posted by aikidokid
Quote:
Originally Posted by Hack
:o :o And I just read that as well!
Time for a break me thinks :lol: :lol:
Hack, is there a quick way to use this and intercept whether the path did not exist and do a yes/no message box to approve the creation?
used this in my current project and really saved time.
Sure....Code:Dim mbResponse As VbMsgBoxResult
If Dir$("d:\test\myfolder", vbDirectory) = vbNullString Then
mbResponse = MsgBox("The folder does not exist. Would you like me to create it for you?", vbYesNo + vbQuestion, "Create Folder")
If mbResponse = vbYes Then
MakeSureDirectoryPathExists "d:\test\myfolder\"
End If
End If