Jump to content

NLCbanner2024.jpg.2478be509670e60c2d6efd04834b8b47.jpg

Another nice script to sequence name a folder of files


Recommended Posts

Following on from my previous thread, here is another script to take all the files in a folder and rename them in an number sequence ready for processing.

It will also preserve the file extensions as well.

Ie take a load of files in the c:\temp directory and name them to

Moon_00001.avi

Moon_00002.avi

Moon_00003.avi

Nice for getting files ready for registax or merging lots folders together with the same file names.

As usual, please test this on dummy data as I will not be held responsible for any data loss or machine corruption.

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''
'' Copyright Catanonia 2010
''
''
''
'' Script file for renaming files and putting them into numeric order. It will keep the file extensions of the files.
''
'' Variables that need to be complete are below
''
'' sFolder = The directory of your files without the backspace
'' sPreName = The characters to be aded to the front of each file
'' sStart = The first number of the file sequence
''
'' Notes
''
'' eg FolderFileOrder "c:\temp" "moon" 75 would rename all files in c:\temp to moon_00075.xxx etc
''
''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

On Error Resume Next
Dim fso, folder, files, sFolder, iCount
Dim strPaddedName
Dim pFileArray(3000,1)
Set fso = CreateObject("Scripting.FileSystemObject")
sFolder = Wscript.Arguments.Item(0)
sPreName = Wscript.Arguments.Item(1)
sStart = Wscript.Arguments.Item(2)

If sFolder = "" Then
Wscript.Echo "No Folder parameter was passed"
Wscript.Quit
End If
If sPreName = "" Then
Wscript.Echo "No Name parameter was passed"
Wscript.Quit
End If
If sStart = "" Then
Wscript.Echo "No Start parameter was passed"
Wscript.Quit
End If
Set folder = fso.GetFolder(sFolder)
Set files = folder.Files
''
'' Get the list of files into the array
''
iCount = 0
For each folderIdx In files
pFileArray(iCount,0) = folderIdx.Name
pFileArray(iCount,1) = Right(folderIdx.Name, 4)
icount = iCount + 1
Next
''
'' Rename the files
''
For i = 0 to iCount - 1
fso.MoveFile sFolder + "\" + pFileArray(i,0), sFolder + "\" + sPreName + "_" + PadDigits(sStart + i,5) + pFileArray(i,1)
Next


Function PadDigits(n, totalDigits)

PadDigits = Right(String(totalDigits,"0") & n, totalDigits)

End Function
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. By using this site, you agree to our Terms of Use.