0

私が取り組んでいる vbscript に問題があります。スクリプトは名前を変更し、いくつかの FTP ログ ファイルをあるフォルダーから別のフォルダーに移動します。スクリプトは機能していますが、delete_junkfiles.log というファイルがあることに気付きましたが、このファイルの名前を変更したり移動したりせず、ソース フォルダーにそのまま残します。

現在、スクリプトはすべてのファイルの名前を変更して移動しています。ファイルの名前が変更されてから移動されても、スクリプトはファイルが見つからないというエラーをスローします。可能であれば、これも修正したいと思います....

vbscript の専門家なら、これはおそらく本当に簡単だと思いますが、私は vbs にかなり慣れていないので、delete_junkfiles.log を無視してそのままにしておく方法がわかりません。あなたが私にできるどんな助けも大歓迎です。以下は私のスクリプトです....

Dim WshShell, FileManagement, BrowseDialogBox, SelectedFolder, OldString, NewString, FullPath, TheFolder, FileList
Dim File, ThisFile, TheString, AlreadyRenamed, TempName, FlagName, Success, FindFlag, NewName, Dummy

Set WshShell = WScript.CreateObject("WScript.Shell")
Set FileManagement = WScript.CreateObject ("Scripting.FileSystemObject")
Set BrowseDialogBox = WScript.CreateObject("Shell.Application")
Set SelectedFolder = BrowseDialogBox.BrowseForFolder(0, "Select the folder containing the files you want to rename.", &H0001)

If InStr(1, TypeName(SelectedFolder), "Folder") = 0 Then
Wscript.Quit
Else
OldString = InputBox("Enter the characters in the filename that you want to replace","Rename Files")
If OldString = "" Then Wscript.Quit

NewString = InputBox("Enter the characters that you want to replace them with","Rename Files")
If NewString = "" Then Wscript.Quit
End If

FullPath = SelectedFolder.ParentFolder.ParseName(SelectedFolder.Title).Path

Set TheFolder = FileManagement.GetFolder(FullPath)
Set FileList = TheFolder.Files
Success = 0


ThisFile = File.Name
TheString = InStr(ThisFile, OldString)
AlreadyRenamed = InStr(ThisFile, "%")

If (TheString <> 0) AND (AlreadyRenamed = 0) Then
Success = 1

TempName = Replace(ThisFile, OldString, NewString)
FlagName = "%" + TempName
File.Name = FlagName
End If
Next

For Each File in FileList
ThisFile = File.Name
FindFlag = InStr(ThisFile, "%")


If FindFlag <> 0 Then
NewName = Replace(ThisFile, "%", "")
File.Name = NewName
End If
Next

'Move the files
For Each File in FileList
FileManagement.MoveFile "C:\Users\lislej\Desktop\test_move\*.log", "C:\Users\lislej\Desktop\test_move_to\"
Next

If Success = 1 Then
Dummy = WshShell.Popup ("Rename Files operation complete!",5,"Rename Files",64)
Else
Dummy = WshShell.Popup ("Rename Files operation failed! Please repeat the operation.",0,"Rename Files",16)
End If

Wscript.Quit
4

2 に答える 2