I need a script will remove the leading zero from the names of about 20k folders

I need a script will remove the leading zero from the names of about 20k folders.

The folders are in one location (F:\Work), and have sub folders and files within them that should not be affected.

The folders in question all have 6 digits and need to have the leading 0 removed so that they only have 5 digits.

i.e.

f:\work\000123 would be changed to f:\work\00123.
DebbieFostAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
Try this batch script; it's currently in test mode and will only display the "ren" commands it would normally run; remove the uppercase ECHO in line 7 to run it for real. While running, no files may be open in the folders, otherwise the names can't be changed. The script can be run several times, it will only process folder names starting with a zero, a length of 6, and consisting of exactly 6 digits.
@echo off
setlocal enabledelayedexpansion
set SourceFolder=F:\Work
for /f "delims=" %%a in ('dir /a:d /b "%SourceFolder%\0*.*" ^| findstr.exe "^[0][0-9][0-9][0-9][0-9][0-9]$"') do (
	set NewName=%%a
	echo %%a --^> !NewName!
	ECHO ren "%SourceFolder%\%%a" "!NewName:~1,5!" 
)

Open in new window

0
exx1976Commented:
Set oFS = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFS.GetFolder("F:\Work")
For each oFile in oFolder.Files
    oFile.name = Right(oFile.Name,(Len(oFile.Name)-1))
Next
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.