Results 1 to 10 of 10

Thread: Folder File.

  1. #1

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    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?

  2. #2
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    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.

  3. #3

  4. #4

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    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?

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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 tried
    VB Code:
    1. MkDir "c:\Hack\Hack1\"
    MkDir would return an error. In order to make that folder list, you would have to do
    VB Code:
    1. MkDir "c:\Hack\"
    2. MkDir "c:\Hack\Hack1\"
    If you need to make multiple folders with one pass, then user the MakeSureDirectoryPathExists API.

  6. #6
    Addicted Member
    Join Date
    May 2004
    Location
    Nagpur, India
    Posts
    228

    Re: Folder File.

    Use MakeSureDirectoryPathExists.
    It will create all the folders in 1 shot.
    http://msdn.microsoft.com/library/de...pathexists.asp

  7. #7
    Addicted Member Redangel's Avatar
    Join Date
    Oct 2005
    Location
    England
    Posts
    214

    Red face Re: Folder File.

    or you could use this code

    Put this in you general declaration section

    VB Code:
    1. Private Declare Function MakeSureDirectoryPathExists _
    2.      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:
    1. MakeSureDirectoryPathExists App.Path & "\FOLDER NAME\"
    2.     MakeSureDirectoryPathExists App.Path & "\FOLDER NAME\"
    Last edited by si_the_geek; Jan 16th, 2006 at 10:49 AM. Reason: removed inappropriate comment

  8. #8

    Re: Folder File.

    MakeSureDirectoryPathExists is the way I'd do it to.

    Straight out of the API guide
    VB Code:
    1. Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As Long
    2. Private Sub Form_Load()
    3.     'KPD-Team 2000
    4.     'URL: [url]http://www.allapi.net/[/url]
    5.     'E-Mail: [email][email protected][/email]
    6.     'create the directory "c:\this\is\a\test\directory\", if it doesn't exist already
    7.     MakeSureDirectoryPathExists "c:\this\is\a\test\directory\"
    8. End Sub

  9. #9
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    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!

  10. #10
    Addicted Member
    Join Date
    May 2004
    Location
    Nagpur, India
    Posts
    228

    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
  •  



Click Here to Expand Forum to Full Width