vbs脚本:MoveFile
2010年08月08日
Rem : =========== 将文件 file 移动到文件夹 folder 中,相当于剪切操作 Rem : =========== file必须存在 Rem : =========== folder必须存在且属性不能为只读 Rem : =========== foler中不能存在与file同名的文件或文件夹 Sub MoveFile( 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, "MoveFile", "File : " & f1 & " does not exist" EndIfIf fso.folderexists(f2)=False ThenErr.Raise vbObjectError+128, "MoveFile", "Folder : " & f2 & " does not exist" EndIfDim f f = f2 & "\" & fso.GetFileName(f1)If fso.fileexists(f) = True Or fso.folderexists(f) = True ThenErr.Raise vbObjectError+128, "MoveFile", f & " already exists" EndIfDim errMsg OnError Resume Next fso.MoveFile f1, f2 & "\"IfErr.Number 0 Then errMsg = Err.Description OnError Goto 0 Err.Raise vbObjectError+128, "MoveFile", errMsg & vbNewLine & _ " file:" & vbTab & file & vbNewLine & _ " folder:" & vbTab & folderExitSubEndIfEndSub
2010年08月08日
Rem : =========== 将文件 file 移动到文件夹 folder 中,相当于剪切操作 Rem : =========== file必须存在 Rem : =========== folder必须存在且属性不能为只读 Rem : =========== foler中不能存在与file同名的文件或文件夹 Sub MoveFile( 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, "MoveFile", "File : " & f1 & " does not exist" EndIfIf fso.folderexists(f2)=False ThenErr.Raise vbObjectError+128, "MoveFile", "Folder : " & f2 & " does not exist" EndIfDim f f = f2 & "\" & fso.GetFileName(f1)If fso.fileexists(f) = True Or fso.folderexists(f) = True ThenErr.Raise vbObjectError+128, "MoveFile", f & " already exists" EndIfDim errMsg OnError Resume Next fso.MoveFile f1, f2 & "\"IfErr.Number 0 Then errMsg = Err.Description OnError Goto 0 Err.Raise vbObjectError+128, "MoveFile", errMsg & vbNewLine & _ " file:" & vbTab & file & vbNewLine & _ " folder:" & vbTab & folderExitSubEndIfEndSub