|
-
Nov 23rd, 2000, 09:32 AM
#1
Thread Starter
Junior Member
Well of all the help i got from this boared i have been able to finish a lot of things on the program i was making, but i have this problem that is the main part of the program. It is a file copy problem:
Code:
Private Sub backup_Click()
Dim MyData As String
Dim dData As String
MyData = App.Path & "\Data\Bin"
dData = App.Path & "\Data\Backup"
FileCopy "MyData", "dData"
Then someone said that you don't use quoted but then if you replace the filecopy without quotes it still doesnt work.
FileCopy MyData, dData
Then if you try to put parenthesese like in an example it wants a = sign.
FileCopy(MyData, dData)
But when you put in an equal sign
FileCopy = MyData, dData
It still gives an error, help!!
As you can see i've tried many diffrent ways to try to get the line
FileCopy "MyData", "dData" to work. But it just doesnt seem to, please help! Thanks!
Dreys
"Your worst enemy is your greatest teacher."
-
Nov 23rd, 2000, 09:40 AM
#2
well, is the file your trying to copy already open? What was your original error?
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Nov 23rd, 2000, 10:11 AM
#3
MyData = App.Path & "\Data\Bin"
dData = App.Path & "\Data\Backup"
Does Bin exist?
Does Backup exist?
Is it a folder or a file?
-
Nov 23rd, 2000, 10:21 AM
#4
Addicted Member
I guess you are trying to copy multiple files, as you are not specifing a file name in your MyData and dData variables. Unfortunatly you are going to have to explicitly tell FileCopy what the file names of what you want to copy are.
FileCopy App.Path & "\Data\Bin" & file1.dat", = App.Path & "\Data\Backup\File2.dat"
FileCopy App.Path & "\Data\Bin" & file2.dat", = App.Path & "\Data\Backup\File2.dat"
etc.
Hope this helps.
-
Nov 23rd, 2000, 10:42 AM
#5
Thread Starter
Junior Member
For the comments on does bit exist and does backup exist.
Bin is the folder i want to be copied, backup is the folder i want to be created. So that way backup now has the bin files & or folder. I am trying to copy entire folders from one spot to another.
Dreys
"Your worst enemy is your greatest teacher."
-
Nov 23rd, 2000, 10:56 AM
#6
FileCopy is not designed to move multiple files.
Use the SHFileOperation api function to do this.
Code:
Public 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
Public Const FO_MOVE = &H1
Public Const FO_COPY = &H2
Public Const FO_DELETE = &H3
Public Const FO_RENAME = &H4
Public Const FOF_SILENT = &H4
Public Const FOF_RENAMEONCOLLISION = &H8
Public Const FOF_NOCONFIRMATION = &H10
Public Const FOF_SIMPLEPROGRESS = & H100
Public Const FOF_ALLOWUNDO = &H40
Public Declare Function SHFileOperation _
Lib "shell32.dll" Alias "SHFileOperationA" _
(lpFileOp As SHFILEOPSTRUCT) As Long
Private Sub Command1_Click()
Dim SHF As SHFILEOPSTRUCT
Dim lret As Long
Dim MyData, dData As String
MyData = App.Path & "\Data\Bin\*.*"
dData = App.Path & "\Data\Backup\"
SHF.wFunc = FO_COPY
SHF.hWnd = Me.hWnd
SHF.pFrom = MyData
SHF.pTo = dData
SHF.fFlags = FOF_SILENT
lret = SHFileOperation(SHF)
'Returns 0 if successful
If lret <> 0 Then
MsgBox "Error"
End If
End Sub
-
Nov 23rd, 2000, 10:58 AM
#7
Addicted Member
in that case can i suggest you use the FileSystemObject, it has a copyfolder method that would suit you.
Dim fs as object
Set fs = CreateObject("Scripting.FileSystemObject")
fs.createfolder (App.Path & "\Data\Backup\")
fs.CopyFolder App.Path & "\Data\Bin\*", App.Path & "\Data\Backup\",true
the last parameter tells the FSO to overwrite any duplicate files.
-
Nov 23rd, 2000, 11:37 AM
#8
Thread Starter
Junior Member
darrenl, i used the stuff you gave me and it gave me no errors, but then when i clicked the button it it gave me an error of Path not found. But the error was pointing to the line
fs.CreateFolder (App.Path & "..\Dune2000\Data\Backup")
Specifically. The path isnt found because its suppose to create it...
Im not sure what exactly im suppose to do.
Dreys
"Your worst enemy is your greatest teacher."
-
Nov 23rd, 2000, 11:42 AM
#9
For FSO:
Code:
Dim FSO as Object
Set FSO = CreateObject("Scripting.FileSystemObject")
Dim MyData, dData As String
MyData = App.Path & "\Data\Bin\"
dData = App.Path & "\Data\Backup\"
FSO.MoveFolder MyData, dData
But the API function works as well.
-
Nov 23rd, 2000, 11:44 AM
#10
Addicted Member
To create a folder just use the old ms-dos command mkdir!
ex:
MkDir "C:\test"
-
Nov 23rd, 2000, 11:51 AM
#11
Addicted Member
Dreys, the line
Code:
fs.createfolder (App.Path & "\Data\Backup\")
will create the destination folder before copying the files.
The MoveFolder method that Mathew uses will move the data into your backup folder and not leave files behind. Whereas the copyfolder method will leave files behind. And if the folder destination folder exists an error will be generated, whereas the copyfolder method will overwrite.
Enjoy.
-
Nov 23rd, 2000, 12:03 PM
#12
Originally posted by Jakys
To create a folder just use the old ms-dos command mkdir!
ex:
MkDir "C:\test"
Always check before making a folder to see if it exists already or you will get an error.
Code:
If Not Dir("C:\test", vbDirectory) = "" Then
MkDir "C:\test"
Else
Exit Sub
End If
-
Nov 23rd, 2000, 03:58 PM
#13
Addicted Member
Sorry, forgot that part. But you could also write
on error resume next
before the line where you expect an error. That would prevent an error message to appear (but of course it could be useful to know if the directory exists, then you could create a dir with another name)
[Edited by Jakys on 11-23-2000 at 04:08 PM]
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
|