Truncate file names?

G

Guest

Guest
Archived from groups: microsoft.public.windowsxp.basics (More info?)

I have a series of 200 files with file names in the format 00000### where ###
is a 3-digit number. I'd like to find an easy way to truncate the leading
zeros so that the file name is just ###. I need to preserve the actual
number as opposed to issuing a new series of sequential numbers. Any ideas?
Thanks!
 

Bruce

Distinguished
Apr 2, 2004
391
0
18,780
Archived from groups: microsoft.public.windowsxp.basics (More info?)

"JRSNHECI" <JRSNHECI@discussions.microsoft.com> wrote in message
news:ACA60D76-E791-4A1E-A016-834F59FAB434@microsoft.com...
>I have a series of 200 files with file names in the format 00000### where
>###
> is a 3-digit number. I'd like to find an easy way to truncate the leading
> zeros so that the file name is just ###. I need to preserve the actual
> number as opposed to issuing a new series of sequential numbers. Any
> ideas?
> Thanks!

A batch file renaming programme will do it for you. There are several free
and shareware out there. Try a few freebies first. A good place to start
is here - http://www.pricelessware.org/thelist/fil.htm#Files:%20Renamer -
click link for Files: Renamer or simply scroll down. There are several with
good descriptions for each. Good luck.
Bruce
 
G

Guest

Guest
Archived from groups: microsoft.public.windowsxp.basics (More info?)

"JRSNHECI" <JRSNHECI@discussions.microsoft.com> wrote in message news:ACA60D76-E791-4A1E-A016-834F59FAB434@microsoft.com...
>I have a series of 200 files with file names in the format 00000### where ###
> is a 3-digit number. I'd like to find an easy way to truncate the leading
> zeros so that the file name is just ###. I need to preserve the actual
> number as opposed to issuing a new series of sequential numbers. Any ideas?
> Thanks!

In a batch file called, say "trimmer.bat", add the following lines inside it, and then execute it entering "cmd /v /c <path>trimmer" in a DOS shell after you have navigated to the directory with your files (the /v switch is required to force immediate expansion of environment variables within the for-loop). The <path> isn't needed if you save trimmer.bat in a directory listed in your PATH environment variable. I added D:\Batch to my PATH and that's where I save by .bat files.

File: trimmer.bat
--------------------

@echo off

rem --- MAIN

for %%a in (*) do (
set origname=%%a
set modname=!origname!
call :LeftTrim 0
echo Old name = "!origname!"
echo New name = "!modname!"
ren "!origname!" "!modname!"
echo.
)
goto :EOF

rem --- FUNCTIONS

:LeftTrim
rem - Deletes specified leading prefix character(s), plus any leading space(s)
rem - after the delete. If prefix character omitted, delete leading spaces.
rem - Syntax: call :LeftTrim [char]
rem (uses global variable "modname")
if "%1" == "" goto DelSpace
rem - Use only the first character of the input parameter.
set delchar=%1
set delchar=!delchar:~0,1!
rem - Remove the prefix character(s).
:DelPrefix
if "!modname:~0,1!" == "!delchar!" (
set modname=!modname:~1!
goto DelPrefix
)
rem - Remove any [resultant] leading spaces.
:DelSpace
if "!modname:~0,1!" == " " (
set modname=!modname:~1!
goto DelSpace
)
set delchar=
goto :EOF
 
G

Guest

Guest
Archived from groups: microsoft.public.windowsxp.basics (More info?)

Personally I like this one, and before you ask, no, I'm not on commission!

http://www.bulkrenameutility.co.uk/Main_Intro.php




"JRSNHECI" <JRSNHECI@discussions.microsoft.com> wrote in message
news:ACA60D76-E791-4A1E-A016-834F59FAB434@microsoft.com...
>I have a series of 200 files with file names in the format 00000### where
>###
> is a 3-digit number. I'd like to find an easy way to truncate the leading
> zeros so that the file name is just ###. I need to preserve the actual
> number as opposed to issuing a new series of sequential numbers. Any
> ideas?
> Thanks!