[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
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
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:
Private Sub lastFolder(source, destination)
Dim Mypath As String, iCount As Integer, c As String, e As String, d As String, save As String, fullpath As String
iCount = 0
save = "savegames"
Mypath = source ' Set the path.
fullpath = Mypath & save
MyName = Dir(fullpath, vbDirectory) ' Retrieve the first entry.
Do While MyName <> "" ' Start the loop.
' Ignore the current directory and the encompassing directory.
If MyName <> "." And MyName <> ".." And Not MyName = "user_invalid" Then
'Use bitwise comparison to make sure MyName is a directory.
If (GetAttr(fullpath & MyName) And vbDirectory) = vbDirectory Then
'Copy files to new location
c = fullpath
'MsgBox (c)
e = c
d = destination
iCount = iCount + 1
End If
End If
MyName = Dir ' Get next entry.
Loop
'' Call VBCopyFiles(e, d) ' it represents a directory.
End Sub
Destination:
vb Code:
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?
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
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:
FileCopy fullpath & "\*", d
I receive "Bad file name or number (Error 52)" on that line.
If I use:
vb Code:
Private Sub lastFolder(source, destination)
Dim save As String, fullpath As String, e As String, d As String
Dim MyName As String, iCount As Integer
iCount = 0
e = source
d = destination
MyName = Dir(e, vbDirectory) ' Retrieve the first entry.
Do While MyName <> "" ' Start the loop.
' Ignore the current directory and the encompassing directory.
If MyName <> "." And MyName <> ".." Then
' Use bitwise comparison to make sure MyName is a directory.
If (GetAttr(e & MyName) And vbDirectory) = vbDirectory Then iCount = iCount + 1 'it represents a directory.
End If
fullpath = e & MyName 'Set the path.
MsgBox (MyName) 'Display entry only if it exists
VBCopyFiles fullpath & "\*", d 'This line was the line I changed
MyName = Dir 'Get next entry.
Loop
End Sub
The reason it didn't work when I put "e" was because "e" didn't contain the value for myName.