Link to home
Start Free TrialLog in
Avatar of keith li
keith liFlag for Hong Kong

asked on

Microsft VBScript error: file already exist

Dear All


              I have below vbscript created and run in window task manager, and it works well for a week, and start from yesterday i,m getting "microsoft VBScript runtime error: File already exist" , any idea ?


With CreateObject("Scripting.FileSystemObject")
.MoveFile "\\10.154.105.100\Upload from OC\*.*", "\\10.141.101.60\test"
End With



Keith
ASKER CERTIFIED SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hmm, "Kill" is not "checking"...
Avatar of keith li

ASKER

Yes I found the file with same name exist the target location, but I have another 3 scripts to run different source, but all of them show file name exist, and I'm sure in the target folder don't have the same file name, anyway I will try to use the script in the previous post, and what does it mean if "kill" is not "checking" ?
The kill instruction delete the file given in parameter.
Avatar of Bill Prew
Bill Prew

The question I would ask is what do you want to happen when the file already exists?

  • Copy and overwrite?
  • Do not copy?
  • Other...?


»bp
overwrite it i want
i,m getting "microsoft vbscript compliation error: expected end of statement. can help to check where went wrong ?



dim fso
set fso = CreateObject("Scripting.FileSystemObject")

dim folder
set folder = fso.getFolder "\\10.154.104.101\Upload from FS\*.*"

dim file
for each file in folder.files
    dim Path
    path =  "\\10.141.101.60\test"  & file.name
    if (fso.fileExists(path)) then
        kill path
    end if
    fso .MoveFile "\\10.154.104.101\Upload from FS\*.*" & file.name, path
next
Not sure about the compilation error, but don't make mistakes when you copy / paste code, the "select all"  option is here for this purpose.

path =  "\\10.141.101.60\test"  & file.name
You missed an "\"
fso .MoveFile "\\10.154.104.101\Upload from FS\*.*" & file.name, path
Remove "*.*"