Remove Leading Zero From Filename
File
ren.vbs (6 views)
This script will process all the filenames in a given folder and remove any leading zeroes. You can use the script to remove any unwanted leading characters from filenames.
Also included in the script is a recursive function that can process a folder tree and all files within it.
' Script written by David Barrett
' Copyright 2009
' http://www.cedit.biz/
' This script is licensed under the Creative Commons
' Attribution 2.5 Licence
' http://creativecommons.org/licenses/by/2.5/
'
' You are free to use it for both personal and
' commercial purposes, so long as full attribution
' is given to the author (David Barrett).
'
' This notice must not be removed
'
'
option explicit
dim strSourceFolder
' Change the folder below to the folder containing files with leading zero(es)
strSourceFolder="E:\Test"
dim objFSO, objF
set objFSO=CreateObject("Scripting.FileSystemObject")
set objF=objFSO.GetFolder(strSourceFolder)
RemoveLeadingZeroes objF
set objF=Nothing
set objFSO=Nothing
sub RemoveLeadingZeroes(objFolder)
RemoveLeadingCharacters objFolder, "0"
end sub
sub RemoveLeadingCharacters(objFolder, strChar)
' Remove leading characters from all files in given folder
dim objFile, strName
for each objFile in objFolder.Files
strName=objFile.Name
while Left(strName, 1)=strChar
strName=Mid(strName, 2)
wend
if strNameobjFile.Name then objFile.Name=strName
next
end sub
sub RecursiveRemoveLeadingCharacters(objFolder, strChar)
' Recursively scan the given folder and process all files within it and subfolders
dim objF
for each objF in objFolder.SubFolders
RecursiveRemoveLeadingCharacters objF, strChar
next
RemoveLeadingCharacters objFolder, strChar
set objF=Nothing
