|
-
Apr 9th, 2002, 12:55 AM
#1
completely silent file copy
Hi,
I'm making a backup program and it will be copying over the same file each day so i want to get rid of the "Folder already exsists..overwrite?" prompts
I'm using this as my code
Code:
Private Declare Function SHFileOperation _
Lib "shell32.dll" Alias "SHFileOperationA" _
(lpFileOp As SHFILEOPSTRUCT) As Long
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 Const FO_MOVE = &H1
Private Const FO_COPY = &H2
Private Const FO_DELETE = &H3
Private Const FO_RENAME = &H4
Private Const FOF_SILENT = &H4
and the actual copy bit
Code:
Dim SHF As SHFILEOPSTRUCT
Dim lret As Long
ArrayCount = 1
Do While ArrayCount <= ArrayLimit
SHF.wFunc = FO_COPY
SHF.hwnd = Me.hwnd
SHF.pFrom = Backup(ArrayCount)
SHF.pTo = SaveLocation
SHF.fFlags = FOF_SILENT
lret = SHFileOperation(SHF)
ArrayCount = ArrayCount + 1
Loop
now i thought with the flags set to FOF_SILENT it would not prompt or anything?
Thanks in advance for help!
-
Apr 9th, 2002, 12:59 AM
#2
PowerPoster
Why can't you just use the FileCopy function built into VB?
VB Code:
FileCopy "C:\test", "D:\test"
-
Apr 9th, 2002, 01:01 AM
#3
Can u trap the Error by using:
On Error Resume Next
-
Apr 9th, 2002, 01:01 AM
#4
You can use the filecopy command instead.
do you HAVE to use the method you described?
-
Apr 9th, 2002, 01:01 AM
#5
Originally posted by MidgetsBro
Why can't you just use the FileCopy function built into VB?
VB Code:
FileCopy "C:\test", "D:\test"
AAAAARGH!!!!
-
Apr 9th, 2002, 01:02 AM
#6
PowerPoster
Originally posted by mendhak
AAAAARGH!!!!
LOL! Quick Draw McJew over here
-
Apr 9th, 2002, 01:02 AM
#7
I think the problem is eliminating the win Dialogs....
-
Apr 9th, 2002, 01:05 AM
#8
PowerPoster
Do the Windows dialogs popup when you use FileCopy?
-------------------
I just tried it and I didn't get a copy dialg when I used:
VB Code:
FileCopy "C:\snt2.jpg", "C:\cheap.jpg"
-
Apr 9th, 2002, 01:08 AM
#9
No.... (just tested it)
-
Apr 9th, 2002, 01:09 AM
#10
-
Apr 9th, 2002, 01:10 AM
#11
However, u get a 'permission' denied when coping from loc to same loc.
ie.
VB Code:
Private Sub Form_Load()
FileCopy "C:\test.txt", "C:\test.txt"
End Sub
-
Apr 9th, 2002, 01:15 AM
#12
PowerPoster
Why in the world would you want to copy the same file to the same place? That makes no logical sense.
-
Apr 9th, 2002, 01:17 AM
#13
and yes I want to use that method..
using On Error Resume Next will kill all my error handling won't it?
-
Apr 9th, 2002, 01:19 AM
#14
Why in the world would you want to copy the same file to the same place? That makes no logical sense.
so i have the latest versions of the files all the time, its the easiest way of doing it
-
Apr 9th, 2002, 01:21 AM
#15
PowerPoster
Yes, it will kill all error handling in that sub. You can have it check for specific error numbers though, instead On Error Resume Next, you could have
VB Code:
Private Sub Stuff()
On Error Go To EL
'your stuff here
Exit Sub
EL:
If Err.Number = 9485 Then 'the number of error you want to trap
Resume Next
End If
End Sub
-
Apr 9th, 2002, 01:23 AM
#16
PowerPoster
Originally posted by nzer
so i have the latest versions of the files all the time, its the easiest way of doing it
But if you copy the same file to the same place, you aren't updating anything. He was saying copy the same file over itself. Think of it this way. Try to take a cup, and put it over itself... see what I'm getting at? Maybe if you copied from like C:\CompileFolder to C:\Program Folder then it would work.
-
Apr 9th, 2002, 01:24 AM
#17
Thanks, but..
On Error Resume Next
doesn't get rid of the window that pops up complaining the folder exsists.
heh can it be done ?
-
Apr 9th, 2002, 01:27 AM
#18
Alternatively, can u open the file, make any changes, then save it back out?
-
Apr 9th, 2002, 01:29 AM
#19
PowerPoster
But what I am saying, if you copy a file called C:\file.dat to C:\file.dat, you are copying the same thing to the same place. You did not do anything to update the file, so it is like cloning the file, yet you aren't because you can't put something in the same place that it already is without moving the old file first, but then you would have a copy error because the source would be gone. It's like a paradox sort of thing, it's late, and I only had an hour and 45 min of sleep, so either I'm not thinking straight, or I'm not explaining it right.
-
Apr 9th, 2002, 01:30 AM
#20
Valid point MidgetsBro
-
Apr 9th, 2002, 01:32 AM
#21
heh no you are thinking correctly!
but SAY my program is scheduled to backup every night at 1.00 am.. say the user hasn't changed any files but my backup program still runs, i still want it to be able to copy files (even if they are the same) without it stopping with a question asking if i can overwrite them .. understand?
and it isn't copying like C:\file.file to C:\ file.file it would be like C:\Accounts to //Server/Backup/Accounts
-
Apr 9th, 2002, 01:35 AM
#22
Now I'm completely lost 
Anyway... This didn't give me ANY errors (although the file existed)
VB Code:
Private Sub Form_Load()
FileCopy "C:\test.txt", "C:\New\test.txt"
End Sub
-
Apr 9th, 2002, 01:35 AM
#23
Fanatic Member
hey midgetsbro! did you make the haztek site?
-
Apr 9th, 2002, 01:39 AM
#24
Originally posted by nzer
heh no you are thinking correctly!
but SAY my program is scheduled to backup every night at 1.00 am.. say the user hasn't changed any files but my backup program still runs, i still want it to be able to copy files (even if they are the same) without it stopping with a question asking if i can overwrite them .. understand?
and it isn't copying like C:\file.file to C:\ file.file it would be like C:\Accounts to //Server/Backup/Accounts
I'm lost too.
But in THIS case you won't get an error.
-
Apr 9th, 2002, 01:42 AM
#25
okay maybe i'm crazy lol
gimme 10 mins to try FileCopy
-
Apr 9th, 2002, 01:49 AM
#26
FileCopy isnt' letting me copy the whole directory
i'm using
Code:
Do While ArrayCount <= ArrayLimit
FileCopy Backup(ArrayCount), SaveLocation
ArrayCount = ArrayCount + 1
Loop
where Backup(1) for example may = E:\Comp
and SaveLocation could = C:\Temp
-
Apr 9th, 2002, 02:04 AM
#27
okay..
I think whats causing the trouble is that i'm copying whole DIRS and not just individual files.. SO now you can see why I might want to copy the same directory over the same directory in a different place (in case the files inside are different)... so really my problem is when i try and copy it trys to create the directory and since its there it asks if its okay to overwrite... so how do i stop that popping up
make sense now? (lol this is getting funny)
-
Apr 9th, 2002, 02:06 AM
#28
You know that you have RENAME and SILENT as both &H4 right?
I think this may be the source of your errors.
Should it be &H5 or even &H6?
-
Apr 9th, 2002, 02:30 AM
#29
You know that you have RENAME and SILENT as both &H4 right?
hmm just noticed that.. but i looked in the API viewer thing and it says
Public Const FOF_SILENT = &H4 ' don't create progress/report
and
Public Const FO_RENAME = &H4
.. argggg....
-
Apr 9th, 2002, 02:42 AM
#30
had a hunt around...
FOF_NOCONFIRMATION
does the trick :-)
thanks for all the input
-
Apr 9th, 2002, 07:50 PM
#31
PowerPoster
Originally posted by Vanguard-MnC
hey midgetsbro! did you make the haztek site?
Yes
-
Apr 9th, 2002, 08:06 PM
#32
Frenzied Member
BTW guys, the CopyFile API is very simple to use, and it give you a few more options.
Anyone know if its any faster?
You just proved that sig advertisements work.
-
Apr 9th, 2002, 08:08 PM
#33
Fanatic Member
this post still exists???? p.s. i dont know anything about api so dont ask me
-
Apr 9th, 2002, 08:47 PM
#34
Hyperactive Member
Though your new Const is fine, without that, I would have said: why can't you use use the DOS copy command? it has a "/y" switch to stop over-write-confirm.
VB Code:
'use any method to find the windows \command directory, API is useful for this
Shell windowsCommandDir & "\copy.exe C:\myDir\*.* _
C:\Backup\ /y", vbHide
Then again, i'm not sure, maybe you'd have to map the net drive! (because of DOS)
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
|