-
Aug 12th, 2005, 10:11 AM
#1
Thread Starter
Fanatic Member
[VB6] FileCopy help
Hi, I copied this code right off of a website and I am still getting errors. I have 2 folders, each containing some files and other folders with files. I want to copy one entire directory and replace the other.
The code I have is as follows.
VB Code:
Dim orig_path, new_path As String
orig_path = App.Path & "/Support_Files/Blank_Profile/*.*"
new_path = App.Path & "/Profile/Profile/*.*"
FileCopy orig_path, new_path
MsgBox ("done")
I get an error on the FileCopy line. I am trying to copy files and other directorys, so the actual list from the Blank_Profile looks like so;
Blank_Profile/profile.ini
Blank_Profile/home_base.ini
Blank_Profile/Ship_1/information.ini
Blank_Profile/Ship_2/information.ini
I need to copy all the files as well as the folders ship_1 and the files inside. There are more files but this is just an example. I read you can copy the contents of a directory but none of the code I have works. Please help.
-
Aug 18th, 2005, 02:40 AM
#2
Re: [VB6] FileCopy help
I moved your thread, since it actualy doesn't have anything to do with game or graphics programming...
- ØØ -
-
Aug 18th, 2005, 02:52 AM
#3
Re: [VB6] FileCopy help
If you use the XCOPY command from DOS, it will copy folders. You'd have to shell it.
-
Aug 18th, 2005, 03:02 AM
#4
Re: [VB6] FileCopy help
Try using the FileSystemObject, ie set a reference to Microsoft Scripting Runtime. I'm pretty sure it copies folders & files. eg
VB Code:
Dim fs As New FileSystemObject
Dim orig_path As String, new_path As String
orig_path = App.Path & "/Support_Files/Blank_Profile/*.*"
new_path = App.Path & "/Profile/Profile/"
fs.CopyFolder orig_path, new_path
Set fs = Nothing
Note that you don't need the wildcards in the destination path.
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Aug 18th, 2005, 06:51 AM
#5
Re: [VB6] FileCopy help
VB Code:
Private Type SHFILEOPSTRUCT
hWnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAborted As Boolean
hNameMaps As Long
sProgress As String
End Type
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Const FOF_NOCONFIRMATION = &H10 ' Don't prompt the user.
Const FOF_NOCONFIRMMKDIR = &H200 ' don't confirm making any needed dirs
Const FO_COPY = &H2
Private Function NuCopy(source As String, target As String) As Boolean
'Nucleus
'Copy file(s)/directories from source to destination
'In path of source either file(s) or folder and path of target as folder
'Out: Boolean indicating success
If Right(source, 1) = "\" Then source = Left(source, Len(source) - 1)
If Len(Dir$(target, vbDirectory)) <> 0 And (Len(Dir$(source, vbDirectory)) <> 0 Or Len(Dir$(target, vbDirectory)) <> 0) Then
Dim SHFileOp As SHFILEOPSTRUCT ' structure to pass to the function
With SHFileOp
.wFunc = FO_COPY
.pFrom = source
.pTo = target
.fFlags = FOF_NOCONFIRMATION Or FOF_NOCONFIRMMKDIR
End With
NuCopy = (SHFileOperation(SHFileOp) = 0)
End If
End Function
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
|