0

並外れたスクリプター -

私はこのスクリプトを持っています。これは、ファイル名の最初の 3 文字を取り出してファイル名の後ろに移動するという本来の役割を果たします。確かにもっとうまく書ける部分はありますが、私はただの初心者であり、これが機能させる方法でした。

それについてうまくいかないのは、totalFiles カウントです。古いファイルを 1 として、新しいファイルを 1 としてカウントすることになります。そのため、すべての名前が変更されるフォルダー内の 50 個のファイルの場合、100 個中 50 個と表示されます。

提案?ありがとう。

' 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
4

2 に答える 2

0

ループobjFolder.Files.Countのファイル数を取得するために使用します。

追加した:

.MP3 ファイルのみの数を取得するには、変数からループ内の非 .MP3 ファイルを減算し、totalFiles ではなく totalMP3s という名前を付けます。

于 2013-05-23T14:32:24.337 に答える