Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I noticed on an earlier forum that someone helped a person to rename some files to another particular format.
I am having problems doing the same thing and I am very unfamiliar with COMMAND.exe under Windows 2000 Pro.
This is the script that was given:
@echo off
if "%1"=="GoTo" goto %2
if not "%OS%"=="Windows_NT" goto eof
%comspec% /v:on /c %0 GoTo start
goto eof:start
echo.
echo This program will rename all files from the current directory,
echo and possibly from its subdirectories, following a certain rule.
echo.
echo Press any key to VIEW the renaming process . . .
pause > nul
echo Processing . . .type nul> %temp%.\process.bat
:: To include the files under subdirectories from current
:: directory on the renaming process, add the string ' /R'
:: after the string 'for' on the next line, so it becomes
:: 'for /R' (don't forget the space between the strings)
for %%F in (*.*) do (
set ORIG=%%~nF
set ORIG=!ORIG:-=!
set FILE=!ORIG:~3,-4!
set EXT=!ORIG:~-4,-1!
if not "!FILE!"=="" if not "!EXT!"=="" (
echo REN "%%F" "!FILE!.!EXT!">> %temp%.\process.bat
)
)echo.
type %temp%.\process.bat |MORE
echo The above process is NOT reversible.
echo.
set CH=
:loop
set /P CH=To you wish to execute the above process [Y/N]?
if /i "%CH%"=="Y" (
call %temp%.\process.bat
echo.
echo Operation done.
del %temp%.\process.bat
goto eof
)
if /i "%CH%"=="N" (
echo.
echo Operation aborted
del %temp%.\process.bat
goto eof
)
goto loop:eof
What I have is a folder that contains filenames under inconsistent formats.
The folder contains .jpg files under the following 2 formats:
filenumber.x.jpg (“x” can be any number)
filenumber.jpg
I want all the filenames to conform to: filename.jpg. So I want to strip off the sequence (“.x”) from any filename that contains the sequence.
Could you please help me out and make some modifications to the above script to accommodate the changes?
I would greatly appreciate your help. Also is there a site you could recommend that would provide some good documentation for COMMAND.exe file management methods.
Thank you very much for your time,
Russell

The above description is inaccurate.
I would like to strip off ".x." sequence and replace it with "." in any file that contains the sequence.
Sorry for the confusion

If your folder contains two kind of .jpg files, i.e.
FileName.x.jpg
FileName.jpgwhere x is any sequence, the following solves your problem:
@Echo Off
If %1.==. ( Echo Folder missing & GoTo :EOF )
If not exist %~f1.\Nul ( Echo Folder %~f1 not found & GoTo :EOF )For /F "tokens=1,2 delims=." %%I in ('Dir %~f1.\*.jpg /B /A:-D') Do (
If /I not "%%J"=="jpg" Echo Ren "%%I.%%J.jpg" "%%I.jpg" )Save it naming as you like (e.g. XRen.bat) then type at prompt XRen FolderName.
The script as it is, only displays the files to be renamed. To activate, erase the "Echo" in front of the Ren command when you are sure it works fine for your purpose.
The script works under Win 2K/XP/NT NOT under Win 9X/ME.
If your need is not satisfied by this answer, post again.

Hey I used your script but I got the error :
' and' not recogized as an internal or external command, operable program or batch file.I figured it out though : I replaced '&' with 'and'
Now it works perfectly....thanks!
Do you know of a good site that would have some documentation of renaming files?

About the "and" issue, I suppose it is solved now; About the need of storing the script into the folder containing the files to be renamed, substitute the original Ren command with the following:
Ren "%~f1.\%%I.%%J.jpg" "%%I.jpg"
and you may call XRen from whatever folder.
Regarding a good site about renaming files, I do not understand what you mean, as renaming under some condition is a process highly influenced by the specific need. So what you need is a strong knowledge of batch commands and scripting.
Have a nice day.

Hello IVO,
i've a similar renaming problem, perhaps you can give me an easy hint!?
I've to rename all the files in a folder from
filename.ext to
filenameext.plt(The extension goes into the filename, and each file gets the extension ".plt")
Thanks in advance,
Jens

Check your e-mail in-box, I'm sending you what you requested.
By the way, another time open a new post, not queue after a thread in progress unless your query is strictly related to that.
You may risk to get no help at all.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |