vbs 脚本:CopyFile
2010年08月08日
Rem : =========== 将文件 file 复制到文件夹 folder 中 Rem : =========== file必须存在 Rem : =========== folder必须存在且属性不能为只读 Rem : =========== foler中不能存在与file同名的文件或文件夹 Sub CopyFile( file, folder ) Dim f1, f2 f1 = file f2 = folderIfRight(f1,1) = "\" Then f1 = Left(f1,Len(f1) -1 )IfRight(f2,1) = "\" Then f2 = Left(f2,Len(f2) -1 )If fso.fileexists(f1)=False ThenErr.Raise vbObjectError+128, "CopyFile", "File : " & f1 & " does not exist" ExitSubEndIfIf fso.folderexists(f2)=False ThenErr.Raise vbObjectError+128, "CopyFile", "Folder : " & f2 & " does not exist" ExitSubEndIfDim f f = f2 & "\" & fso.GetFileName(f1)If fso.fileexists(f) = True Or fso.folderexists(f) = True ThenErr.Raise vbObjectError+128, "CopyFile", f & " already exists" ExitSubEndIfDim errMsg OnError Resume Next fso.CopyFile f1, f2 & "\", FalseIfErr.Number 0 Then errMsg = Err.Description OnError Goto 0 Err.Raise vbObjectError+128, "CopyFile", errMsg & vbNewLine & _ " file:" & vbTab & file & vbNewLine & _ " folder:" & vbTab & folderExitSubEndIfEndSub
2010年08月08日
Rem : =========== 将文件 file 复制到文件夹 folder 中 Rem : =========== file必须存在 Rem : =========== folder必须存在且属性不能为只读 Rem : =========== foler中不能存在与file同名的文件或文件夹 Sub CopyFile( file, folder ) Dim f1, f2 f1 = file f2 = folderIfRight(f1,1) = "\" Then f1 = Left(f1,Len(f1) -1 )IfRight(f2,1) = "\" Then f2 = Left(f2,Len(f2) -1 )If fso.fileexists(f1)=False ThenErr.Raise vbObjectError+128, "CopyFile", "File : " & f1 & " does not exist" ExitSubEndIfIf fso.folderexists(f2)=False ThenErr.Raise vbObjectError+128, "CopyFile", "Folder : " & f2 & " does not exist" ExitSubEndIfDim f f = f2 & "\" & fso.GetFileName(f1)If fso.fileexists(f) = True Or fso.folderexists(f) = True ThenErr.Raise vbObjectError+128, "CopyFile", f & " already exists" ExitSubEndIfDim errMsg OnError Resume Next fso.CopyFile f1, f2 & "\", FalseIfErr.Number 0 Then errMsg = Err.Description OnError Goto 0 Err.Raise vbObjectError+128, "CopyFile", errMsg & vbNewLine & _ " file:" & vbTab & file & vbNewLine & _ " folder:" & vbTab & folderExitSubEndIfEndSub