schmir1
asked on
VBScript CopyFile not working when it exists
The CopyFile throws an error if it finds the file and when I added Deletefile then that throws an error if it doesn't find the file. Sometimes I get a permission error. Is it just because it's the desktop?
I need some code that will overwrite the file and not complain.
I need some code that will overwrite the file and not complain.
oFSO.DeleteFile "C:\Documents and Settings\All Users\Desktop\DTLDB.accdb Devtest.lnk",false
ofso.CopyFile "T:\MCL_Dbase\Development_db\DTLDB_SQLVer\Setup_Dev\DTLDB.accdb Dev.lnk","C:\Documents and Settings\All Users\Desktop\DTLDB.accdb Devtest.lnk"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I needed to add the On Error Resume Next before the DeleteFile. I am the administrator on this PC but it will not overwrite a file in the All Users\Desktop space no matter what True/False options I put on the DeleteFile and CopyFile commands.
I only need On Error Resume Next before the DeleteFile command so how do I turn back on the debug error handler after that?
I only need On Error Resume Next before the DeleteFile command so how do I turn back on the debug error handler after that?
On Error Resume Next
oFSO.DeleteFile "C:\Documents and Settings\All Users\Desktop\DTLDB.accdb Test.lnk",true
ofso.CopyFile "T:\MCL_Dbase\Development_db\DTLDB_SQLVer\Setup_Dev\DTLDB.accdb Test.lnk","C:\Documents and Settings\All Users\Desktop\DTLDB.accdb Test.lnk", true
To see the errors you would have to remark out the On Error Resume Next with a '
So the line would be:
'On Error Resume Next
So the line would be:
'On Error Resume Next
ASKER
Don't want to comment it out. I want to see all the real errors.
The following seems to work using the
On Errror GoTo 0
Thanks guys for your help.
The following seems to work using the
On Errror GoTo 0
Thanks guys for your help.
On Error Resume Next 'Need to turn of error handling in case the lnk file does not exist
oFSO.DeleteFile "C:\Documents and Settings\All Users\Desktop\DTLDB.accdb Test.lnk",true
On Error GoTo 0
ofso.CopyFile "T:\MCL_Dbase\Development_db\DTLDB_SQLVer\Setup_Dev\DTLDB.accdb Test.lnk","C:\Documents and Settings\All Users\Desktop\DTLDB.accdb Test.lnk", true
Set WshNetwork = WScript.CreateObject("WScr
strUser = WshNetwork.UserName
On Error Resume Next
'Change to 1 if you want it to overwrite
fso.CopyFile "\\SERVER\netlogon\faculty
Set fs = Nothing
end