|
-
Jan 15th, 2006, 11:05 PM
#1
Thread Starter
Fanatic Member
Folder File.
I have a specified path for a file, for example, C:\Folder1\1.txt, and I want to use filecopy to copy a file to that location. Now, if Folder1 does not exist, what is the easiest way to acheive my goal?
-
Jan 15th, 2006, 11:11 PM
#2
Fanatic Member
Re: Folder File.
Is your goal to just copy the file to that folder? If folder1 does not exist then you could just use the MkDir() function to create it before you copy to the folder...
Otherwise I'm confused about what you mean.
-
Jan 15th, 2006, 11:12 PM
#3
Re: Folder File.
You may use Dir$() function to check if folder exist first:
VB Code:
If Dir$("c:\MyDir", vbDirectory) = "" Then
MkDir "c:\MyDir"
End If
-
Jan 15th, 2006, 11:27 PM
#4
Thread Starter
Fanatic Member
Re: Folder File.
Well, there may be a number of different non-existant folders before the file, and I won't necessarily know what they are. Is my only option to programatically find the directory the folder will be in and use MkDir?
-
Jan 16th, 2006, 06:16 AM
#5
Re: Folder File.
If you don't know what they are, then how can you find them?
If they don't exist, then how will you know what to make?
This is very confusing.
Also, MkDir will only make one folder at a time. For example, if you triedMkDir would return an error. In order to make that folder list, you would have to do
VB Code:
MkDir "c:\Hack\"
MkDir "c:\Hack\Hack1\"
If you need to make multiple folders with one pass, then user the MakeSureDirectoryPathExists API.
-
Jan 16th, 2006, 06:41 AM
#6
Addicted Member
Re: Folder File.
Use MakeSureDirectoryPathExists.
It will create all the folders in 1 shot.
http://msdn.microsoft.com/library/de...pathexists.asp
-
Jan 16th, 2006, 07:49 AM
#7
Addicted Member
Re: Folder File.
or you could use this code
Put this in you general declaration section
VB Code:
Private Declare Function MakeSureDirectoryPathExists _
Lib "imagehlp.dll" (ByVal lpPath As String) As Long
and when you want your program to create the file folders you require then put this code in that procedure
VB Code:
MakeSureDirectoryPathExists App.Path & "\FOLDER NAME\"
MakeSureDirectoryPathExists App.Path & "\FOLDER NAME\"
Last edited by si_the_geek; Jan 16th, 2006 at 10:49 AM.
Reason: removed inappropriate comment
-
Jan 16th, 2006, 10:12 AM
#8
Banned
Re: Folder File.
MakeSureDirectoryPathExists is the way I'd do it to.
Straight out of the API guide
VB Code:
Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As Long
Private Sub Form_Load()
'KPD-Team 2000
'URL: [url]http://www.allapi.net/[/url]
'create the directory "c:\this\is\a\test\directory\", if it doesn't exist already
MakeSureDirectoryPathExists "c:\this\is\a\test\directory\"
End Sub
-
Jan 16th, 2006, 10:23 AM
#9
Re: Folder File.
Some people don't bother reading replies at all which results in multiduplicate posts.
Hack - Today, 06:16 AM Post #5
mayurvb - Today, 06:41 AM Post #6 (25 minutes later)
Redangel - Today, 07:49 AM Post #7 (1 hour 33 minutes later)
Atribune - Today, 10:12 AM Post #8 (almost 4! hours later)
Really is amazing!
-
Jan 16th, 2006, 12:17 PM
#10
Addicted Member
Re: Folder File.
I really missed that last line from the post # 5.
Sincere apologies! :-(
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
|