优秀的编剧——
我有这个脚本。它完成了它应该做的工作,即提取文件名的前三个字符并将它们移动到文件名的后面。当然有些部分可以写得更好,但我只是一个初学者,这是我可以让它工作的一种方式。
不起作用的是 totalFiles 计数。它最终将旧文件计为 1,将新文件计为 1。因此,对于一个文件夹中的 50 个文件都被重命名,它表示 50 of 100。
建议?谢谢。
' Renames MP3s in C:\Directory to move the 3 digit channel number to the end of the filename.
' If the new file name already exists, it is skipped.
' If the file has already been renamed, it is skipped.
Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = "C:\Directory"
Dim sChannel, sRtFile, sNewFile, intCount, totalFiles
intCount = 0
totalFiles =0
Set objFolder = objFSO.GetFolder(objStartFolder)
Set colFiles = objFolder.Files
For Each objFile in colFiles
totalFiles = totalFiles + 1
If UCase(objFSO.GetExtensionName(objFile.name)) = "MP3" Then
sOldFile = objFSO.GetBaseName(objFile)
sChannel = Left(sOldFile, Len(sOldFile) - 14)
sRtFile = Right(sOldFile, Len(sOldFile) - 3)
sNewFile = sRtFile + sChannel
'Wscript.Echo sChannel
If sChannel = "001" Then
sNewFilePath = objStartFolder + "\" + sNewFile + ".mp3"
If objFSO.FileExists(sNewFilePath) Then
Else
objFSO.MoveFile objFile.Path, sNewFilePath
intCount = intCount + 1
End If
End If
If sChannel="002" Then
sNewFilePath = objStartFolder + "\" + sNewFile + ".mp3"
If objFSO.FileExists(sNewFilePath) Then
Else
objFSO.MoveFile objFile.Path, sNewFilePath
intCount = intCount + 1
End If
End If
If sChannel="003" Then
sNewFilePath = objStartFolder + "\" + sNewFile + ".mp3"
If objFSO.FileExists(sNewFilePath) Then
Else
objFSO.MoveFile objFile.Path, sNewFilePath
intCount = intCount + 1
End If
End If
If sChannel="004" Then
sNewFilePath = objStartFolder + "\" + sNewFile + ".mp3"
If objFSO.FileExists(sNewFilePath) Then
Else
objFSO.MoveFile objFile.Path, sNewFilePath
intCount = intCount + 1
End If
End If
If sChannel="005" Then
sNewFilePath = objStartFolder + "\" + sNewFile + ".mp3"
If objFSO.FileExists(sNewFilePath) Then
Else
objFSO.MoveFile objFile.Path, sNewFilePath
intCount = intCount + 1
End If
End If
If sChannel="006" Then
sNewFilePath = objStartFolder + "\" + sNewFile + ".mp3"
If objFSO.FileExists(sNewFilePath) Then
Else
objFSO.MoveFile objFile.Path, sNewFilePath
intCount = intCount + 1
End If
End If
If sChannel="007" Then
sNewFilePath = objStartFolder + "\" + sNewFile + ".mp3"
If objFSO.FileExists(sNewFilePath) Then
Else
objFSO.MoveFile objFile.Path, sNewFilePath
intCount = intCount + 1
End If
End If
If sChannel="008" Then
sNewFilePath = objStartFolder + "\" + sNewFile + ".mp3"
If objFSO.FileExists(sNewFilePath) Then
Else
objFSO.MoveFile objFile.Path, sNewFilePath
intCount = intCount + 1
End If
End If
End If
Next
If intCount < totalFiles Then
Wscript.Echo intCount & " of " & totalFiles & " files renamed." & vbCrLf & "Some files appear to have already been renamed."
Else
Wscript.Echo intCount & " of " & totalFiles & " files renamed."
End If