Results 1 to 5 of 5

Thread: [RESOLVED] Copying files without container folder

  1. #1

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,346

    Resolved [RESOLVED] Copying files without container folder

    Hi,

    I'm using this code to copy from destination to another, this work fine. However, the source files are in a folder:

    example:

    C:\saves\games\game1.game

    and when I use the above linked to code it copies the whole structure to the new location whereas I only want game1.gam.

    example:

    D:\saves\game1.game

    Any ideas?

    Thanks,


    Nightwalker
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,536

    Re: Copying files without container folder

    Like this maybe?
    Code:
    Call VBCopyFolder("C:\saves\games\game1.game", "D:\saves\game1.game")
    If it works, you may want to rename the function a bit. It could be misleading, since you are not copying a folder, but copying just a file.

    P.S. You can always use VB's FileCopy too
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,346

    Re: Copying files without container folder

    Well, I have discovered that it is not the copy method causing the problem but infact the code to find the last folder as seen here. For some reason the last folder gets appended to the destination path.

    This is what I have tried so far to fix the problem:

    vb Code:
    1. Private Sub lastFolder(source, destination)
    2. Dim Mypath As String, iCount As Integer, c As String, e As String, d As String, save As String, fullpath As String
    3.  iCount = 0
    4.  save = "savegames"
    5.  Mypath = source  ' Set the path.
    6.  fullpath = Mypath & save
    7.  MyName = Dir(fullpath, vbDirectory) ' Retrieve the first entry.
    8.  Do While MyName <> "" ' Start the loop.
    9.    ' Ignore the current directory and the encompassing directory.
    10.     If MyName <> "." And MyName <> ".." And Not MyName = "user_invalid" Then
    11.        'Use bitwise comparison to make sure MyName is a directory.
    12.       If (GetAttr(fullpath & MyName) And vbDirectory) = vbDirectory Then
    13.               'Copy files to new location
    14.            c = fullpath
    15.            'MsgBox (c)
    16.            e = c
    17.            d = destination
    18.           iCount = iCount + 1
    19.    End If
    20.    End If
    21.          MyName = Dir   ' Get next entry.
    22.   Loop
    23.       ''   Call VBCopyFiles(e, d)  ' it represents a directory.
    24. End Sub

    Destination:

    vb Code:
    1. destination = GetSpecialFolder(CSIDL_PERSONAL) & "\Rockstar Games\GTA IV\"

    However, for some reason myName directory still ends up as part of the destination and I can't see why?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,536

    Re: Copying files without container folder

    You are copying a folder not files. Because of this, the API is creating the same folder structure at your destination. Try this instead, if you just want the file contents of the folder copied
    Code:
    Call VBCopyFiles(e & "\*", d )
    See this for more information on the structure you are filling out for the API
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,346

    Re: Copying files without container folder

    I tried that but nothing happens! That is no files nor folders get copied to the destination directory.

    Edit:

    If I put:

    vb Code:
    1. FileCopy fullpath & "\*", d

    I receive "Bad file name or number (Error 52)" on that line.

    If I use:

    vb Code:
    1. Private Sub lastFolder(source, destination)
    2. Dim save As String, fullpath As String, e As String, d As String
    3. Dim MyName As String, iCount As Integer
    4. iCount = 0
    5.  e = source
    6.  d = destination
    7. MyName = Dir(e, vbDirectory)   ' Retrieve the first entry.
    8. Do While MyName <> ""   ' Start the loop.
    9.    ' Ignore the current directory and the encompassing directory.
    10.   If MyName <> "." And MyName <> ".." Then
    11.       ' Use bitwise comparison to make sure MyName is a directory.
    12.       If (GetAttr(e & MyName) And vbDirectory) = vbDirectory Then iCount = iCount + 1 'it represents a directory.
    13.    End If
    14.     fullpath = e & MyName 'Set the path.
    15.  
    16.   MsgBox (MyName) 'Display entry only if it exists
    17.   VBCopyFiles fullpath & "\*", d 'This line was the line I changed
    18.   MyName = Dir   'Get next entry.
    19.    
    20.    Loop
    21.  
    22. End Sub

    The reason it didn't work when I put "e" was because "e" didn't contain the value for myName.
    Last edited by Nightwalker83; Dec 28th, 2011 at 06:57 PM. Reason: Adding more!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

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