ianmclachlan
asked on
Over-writing files with objname.copyhere function in VBscript
Hi Guys,
Simple question for the VBscript gurus out there.
I have a written a VBscript that copies desktop & doc's folder from 4 PC's to a USB hard drive as a bit of extra backup security. However, when I run the script 99.9% of files copy over without issue, but a number of files come up saying "file exists in destination..." and stop the script. These are files like desktop.ini etc... I don't understand why they flag up as the file should not exist at the destination, as it should be blank - The script deletes all folders/files prior to runnning and this has been tested as true. Anyway, I thought the best way to resolve this would be to set the script to overwrite any existing files. But can't seem to get it to work.
Here is an extract from my script:
' ******************* xxxx PC ************************** ***
if filesys.folderexists(xxxxP C3) then
shell.Popup "Copying xxxx Docs and Desktop data to Hard Drive", 10, Timer, 64
objFolder5.CopyHere "\\xxxx-pc\Users\xxxx\Docu ments\*.*" , FOF_CREATEPROGRESSDLG
objFolder6.CopyHere "\\xxxx-pc\Users\xxxx\desk top\*.*", FOF_CREATEPROGRESSDLG
shell.Popup "BACKUP COMPLETED.... CHECK !!!!! ", 10, Timer, 64
else
shell.Popup "I cannot see the xxxx PC 3. ** This has NOT been backup **", 10, Timer, 64
end if
I was trying to append , true .... as this was suggested as the correct method to overwrite:
eg. objFolder5.CopyHere "\\xxxx-pc\Users\xxxx\Docu ments\*.*" , true, FOF_CREATEPROGRESSDLG
But I seem to get an error. Probably a bracket or quote missing somewhere, so thought I would ask.
Any help, much appreciated.
IM
Simple question for the VBscript gurus out there.
I have a written a VBscript that copies desktop & doc's folder from 4 PC's to a USB hard drive as a bit of extra backup security. However, when I run the script 99.9% of files copy over without issue, but a number of files come up saying "file exists in destination..." and stop the script. These are files like desktop.ini etc... I don't understand why they flag up as the file should not exist at the destination, as it should be blank - The script deletes all folders/files prior to runnning and this has been tested as true. Anyway, I thought the best way to resolve this would be to set the script to overwrite any existing files. But can't seem to get it to work.
Here is an extract from my script:
' ******************* xxxx PC **************************
if filesys.folderexists(xxxxP
shell.Popup "Copying xxxx Docs and Desktop data to Hard Drive", 10, Timer, 64
objFolder5.CopyHere "\\xxxx-pc\Users\xxxx\Docu
objFolder6.CopyHere "\\xxxx-pc\Users\xxxx\desk
shell.Popup "BACKUP COMPLETED.... CHECK !!!!! ", 10, Timer, 64
else
shell.Popup "I cannot see the xxxx PC 3. ** This has NOT been backup **", 10, Timer, 64
end if
I was trying to append , true .... as this was suggested as the correct method to overwrite:
eg. objFolder5.CopyHere "\\xxxx-pc\Users\xxxx\Docu
But I seem to get an error. Probably a bracket or quote missing somewhere, so thought I would ask.
Any help, much appreciated.
IM
Hi,
You should be able to use
FOF_NOCONFIRMATION + FOF_NOERRORUI + FOF_CREATEPROGRESSDLG
as your flags.
So define your flags with
FOF_NOCONFIRMATION = &H10
FOF_CREATEPROGRESSDLG = &H100
FOF_NOERRORUI = &H400
And use the plus method to add the parameters and see how that goes.
Regards,
Rob.
You should be able to use
FOF_NOCONFIRMATION + FOF_NOERRORUI + FOF_CREATEPROGRESSDLG
as your flags.
So define your flags with
FOF_NOCONFIRMATION = &H10
FOF_CREATEPROGRESSDLG = &H100
FOF_NOERRORUI = &H400
And use the plus method to add the parameters and see how that goes.
Regards,
Rob.
ASKER
Hi Guys,
Thanks for the replies. Unfortunately it's still popping up with the message that there are files with the same name: "Replace, Skip and Let me decide the destination" option popup.
I declared the Const and added the extra flags as suggested
objFolder5.CopyHere "\\xxxx-pc\Users\xxxx\Docu ments\*.*" , FOF_NOCONFIRMATION + CREATEPROGRESSDLG + FOF_NOERRORUI
objFolder6.CopyHere "\\xxxx-pc\Users\xxxx\desk top\*.*", FOF_NOCONFIRMATION + CREATEPROGRESSDLG + FOF_NOERRORUI
I noticed the flag definition was different between your suggestions (&H10 &H10&) - I tired both, but still got the popup. I also tried with just one - FOF_NOCONFIRMATION rather than appending + etc... again, still the same.
It's a Windows 10 PC, whether that make a difference. Anything else that I could try?
Really appreciate your time and comments.
Regards,
IM
Thanks for the replies. Unfortunately it's still popping up with the message that there are files with the same name: "Replace, Skip and Let me decide the destination" option popup.
I declared the Const and added the extra flags as suggested
objFolder5.CopyHere "\\xxxx-pc\Users\xxxx\Docu
objFolder6.CopyHere "\\xxxx-pc\Users\xxxx\desk
I noticed the flag definition was different between your suggestions (&H10 &H10&) - I tired both, but still got the popup. I also tried with just one - FOF_NOCONFIRMATION rather than appending + etc... again, still the same.
It's a Windows 10 PC, whether that make a difference. Anything else that I could try?
Really appreciate your time and comments.
Regards,
IM
Those options seem not to work if you are using wildcards - they do for a single file.
ASKER
Thanks Qlemo. Do I take it then it's not possible, or requires a complete re-write to make it work?
IM
IM
If you don't need a dialog box during the copy showing the progress you could just use the filesystem CopyFile method. Do you need status during the copy, or could it just be done silently?
»bp
»bp
ASKER
So is it the fact I'm using the windows system explorer to copy that is causing this issue? I put in the progress bar to give the user some comfort that the backup is running.
IM
IM
As a bit of a more reliable option, you could shell out to
cmd /c xcopy /y /f %source% %destination%
With a few other switches. This would display the command prompt and the files being copied to the user.
Rob.
cmd /c xcopy /y /f %source% %destination%
With a few other switches. This would display the command prompt and the files being copied to the user.
Rob.
ASKER
I think you maybe right. It's frustrating it doesn't work. So I might just shell out and use robocopy to do the backup.
I hate letting these things beat me. Wonder why it won't work.
IM
I hate letting these things beat me. Wonder why it won't work.
IM
Yes, seems to be a feature (bug) of CopyHere when using wildcards that it doesn't honor some or all of the flags. I see it documented on several sites under WinXP, but haven't seen any new chatter on Win10. Seems to be the same symptom in a test here though.
Only other thought depending on number of files and sizes, would be to enumerate the files outside of CopyHere (using FSO) and then invoke a CopyHere for each file. Slower, and if you had a lot of small files might not work that well, but if you only had a few large files might be an option.
I'm assuming you must have large files since you thought they needed to see a progress bar to know "something was still happening"?
»bp
Only other thought depending on number of files and sizes, would be to enumerate the files outside of CopyHere (using FSO) and then invoke a CopyHere for each file. Slower, and if you had a lot of small files might not work that well, but if you only had a few large files might be an option.
I'm assuming you must have large files since you thought they needed to see a progress bar to know "something was still happening"?
»bp
ASKER
Hi Bill,
Yes, I thought about running it through some sort of loop, however, I'm not convinced that this will not be without probem as well.
I think xcopy or robocopy is best, if anything it should be alot quicker and I might not even have the issue. I can't explain why it thinks the file exists on a blank drive during the copy process. Fraught with bugs me thinks. I'll just shell out and use good old dos to solve my problem.
IM
Yes, I thought about running it through some sort of loop, however, I'm not convinced that this will not be without probem as well.
I think xcopy or robocopy is best, if anything it should be alot quicker and I might not even have the issue. I can't explain why it thinks the file exists on a blank drive during the copy process. Fraught with bugs me thinks. I'll just shell out and use good old dos to solve my problem.
IM
Just one other thing I noticed rereading your original post. You mentioned the desktop.ini files. Keep in mind these are flagged in Windows as SYSTEM and HIDDEN files. So a simple DIR or Windows File Explorer may not show them, and a simple DEL or delete may not remove them...
»bp
»bp
ASKER
Yeah, thought about that, however, they are being deleted from the drive. Was having problems removing files from hard drive originally. So broke it up into individual scripts (1.) Remove old backup files from HD 2.) Create Directories and Copy files) and ran them using a batch script. So I know the drive is blank. Seems to be only one PC as well thats causing issues (all are Win 10). Have checked permissions etc... Nothing is different. The whole script just seems buggy. I'll probably have no issues with xcopy.
Thanks for you comments.
IM
Thanks for you comments.
IM
ASKER
Hi Guys,
New problem. Doesn't seem to like spaces in the paths? :(
if filesys.folderexists(xxxxP C3) then
shell.Popup "Copying xxxx3 Docs and Desktop data to Hard Drive", 10, Timer, 64
oShell.Run("xcopy \\xxxx3-pc\c$\Users\xxxx 3\documents\*.* /s/e/y d:\bck\xxxx3\docs\" )
oShell.Run("xcopy \\xxxx3-pc\c$\Users\xxxx 3\desktop\*.* /s/e/y d:\bck\xxxx3\desktopfiles\ " )
else
shell.Popup "I cannot see the xxxx PC 3. ** This has NOT been backup **", 10, Timer, 64
mylog.run("%comspec% /k echo Can't see xxxx 3 PC >> C:\users\xxxx 1\desktop\myfiles\backup_e rrors.txt" ), 0, FALSE
end if
New problem. Doesn't seem to like spaces in the paths? :(
if filesys.folderexists(xxxxP
shell.Popup "Copying xxxx3 Docs and Desktop data to Hard Drive", 10, Timer, 64
oShell.Run("xcopy \\xxxx3-pc\c$\Users\xxxx 3\documents\*.* /s/e/y d:\bck\xxxx3\docs\" )
oShell.Run("xcopy \\xxxx3-pc\c$\Users\xxxx 3\desktop\*.* /s/e/y d:\bck\xxxx3\desktopfiles\
else
shell.Popup "I cannot see the xxxx PC 3. ** This has NOT been backup **", 10, Timer, 64
mylog.run("%comspec% /k echo Can't see xxxx 3 PC >> C:\users\xxxx 1\desktop\myfiles\backup_e
end if
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ended up using robocopy rather than xcopy as I had one or two issues with it. All working fine now.
IM
IM
Open in new window
»bp