help renaming multiple files

April 7, 2011 at 05:20:34
Specs: Windows XP
I have a list of html files in a directory say d:\test.

each file contains " Use SHIFT+ENTER to open the menu (new window)..aspx." as part of the file name.

ex: "USA Use SHIFT+ENTER to open the menu (new window)..aspx.html"
"UK Use SHIFT+ENTER to open the menu (new window)..aspx.html"

Now i need to find and replace " Use SHIFT+ENTER to open the menu (new window)..aspx." in each and every file name. so the above files will convert to the following file names:

"USA.html"
"UK.html"

Please help me with a simple dos batch script.

thanks a lot.


See More: help renaming multiple files

Report •


#1
April 8, 2011 at 03:14:00
Am not 100% certain what you want to do. You say find and replace but don't show anything to replace what is found.

Is this a simple renaming of files?

Did you Google for an answer before asking the question?


Report •

#2
April 10, 2011 at 01:12:26
Hi I need to replace the text from "use shift enter ......aspx"

Report •

#3
April 10, 2011 at 02:40:14
Replace it with what?? Do you mean that you want the files renamed by removing "use shift enter ......aspx" in each filename?

Try this.. When you are satisfied the script will do what you want remove Rem from the Ren command line and delete the Echo command line.

@echo off
cls
setlocal enabledelayedexpansion

pushd d:\test\||echo Pushd failed - job terminated&&exit /b

for /f "tokens=*" %%1 in ('dir /b *.html') do (
    set filename=%%1
        for /f "tokens=1*" %%A in ("!filename!") do (
            set newfilename=%%A
            )
REM ren "!filename!" !newfilename!.html
echo !filename! WILL BE RENAMED !newfilename!.html
                )
popd
    

Did you Google for an answer before asking the question?


Report •

Related Solutions

#4
April 10, 2011 at 10:33:03
Hey thanks man.

Sorry for not being specific.
Replace " Use SHIFT+ENTER to open the menu (new window)..aspx." --- with blank "".

I think the above script posted will not help since i cannot give old file name and new file name.

thanks.


Report •

#5
April 12, 2011 at 01:16:05
I think the above script posted will not help since i cannot give old file name and new file name.

What do you mean? Old filenames and the new filenames will be displayed onscreen for your approval, at this point no files are renamed. If you approve of the changes to be made amend the script as I advised:

When you are satisfied the script will do what you want remove Rem from the Ren command line and delete the Echo command line.

then when you run the script the files will be renamed as was shown onscreen.

Did you Google for an answer before asking the question?


Report •

#6
April 14, 2011 at 05:26:42
Hi,

Sorry for my Ignorance but Thanks for the response, but when i put the above script in a bat file and run. It exits immediately without any clue.

Another thing, there are about 100 files in the directory which contains "Use SHIFT+ENTER to open the menu (new window)" in their file names. So how can i use the above script to rename all the files with replacing the above text without giving all the old file names manually in the bat file.

So here are the list of files:

US1 Use SHIFT+ENTER to open the menu (new window).html
US2 Use SHIFT+ENTER to open the menu (new window).html
FL Use SHIFT+ENTER to open the menu (new window).html
FL2 Use SHIFT+ENTER to open the menu (new window).html

Now in the bat file where should i plug in " Use SHIFT+ENTER to open the menu (new window)" such that the files become:

US1.html
US2.html
FL.html
FL2.html

after renaming.

I didnt understand what to do with script looks too technical for me. Thanks for the help again.


Report •

#7
April 15, 2011 at 01:38:30
Add pause as the last line of the script so that the screen output is displayed. e.g.

@echo off
cls
setlocal enabledelayedexpansion

pushd d:\test\||echo Pushd failed - job terminated&&exit /b

for /f "tokens=*" %%1 in ('dir /b *.html') do (
    set filename=%%1
        for /f "tokens=1*" %%A in ("!filename!") do (
            set newfilename=%%A
            )
REM ren "!filename!" !newfilename!.html
echo !filename! WILL BE RENAMED !newfilename!.html
                )
popd
pause

You do NOT have to enter any part of any filename, simply view the screen output, at this point no files have been renamed. If you are satisfied that the script will do what you want amend the script by removing REM and delete the line starting with echo !filename!..... files will be renamed when you run the amended script.

Did you Google for an answer before asking the question?


Report •

#8
April 17, 2011 at 05:53:03
Hey thanks man for your time. You were very helpful.

Here is the script i put in a bat file.

@echo off
cls
setlocal enabledelayedexpansion

pushd d:\test\||echo Pushd failed - job terminated&&exit /b

for /f "tokens=*" %%1 in ('dir /b *.html') do (
set filename=%%1
for /f "tokens=1*" %%A in ("!filename!") do (
set newfilename=%%A
)
ren "!filename!" !newfilename!.html

)
popd
pause


And here is the output i get on the screen:

A duplicate file name exists, or the file
cannot be found.
A duplicate file name exists, or the file
cannot be found.
A duplicate file name exists, or the file
cannot be found.
A duplicate file name exists, or the file
cannot be found.
Press any key to continue . . .

Actually i didnt understand the script, that's why its taking time for me to get it working.

Can you replicate this renaming part on your end and tell me the output.

Actually, I was using file renamer deluxe to find and replace that part of text from all filenames, but now i just was curious about one click renaming and tried many types of scripts found here, but no good.

Thanks again.


Report •

#9
April 17, 2011 at 18:28:48
I created dummy input files in d:\test\ as you specified with filenames such as:

USA use SHIFT+ENTER to open the menu (new window)..aspx.html

After running the script provided the directory listing of D:\test\ shows:

 Volume in drive D is Master D
 Volume Serial Number is DDDD-DDDD

 Directory of d:\test

Mon 18/04/2011  13:02    <DIR>          .
Mon 18/04/2011  13:02    <DIR>          ..
Mon 18/04/2011  12:58                18 CAN.html
Mon 18/04/2011  12:58                18 IRE.html
Mon 18/04/2011  12:58                18 UK.html
Mon 18/04/2011  12:58                18 USA.html
               4 File(s)            852 bytes

Note that the files have been renamed as you wanted(?).

You asked So how can i use the above script to rename all the files with replacing the above text without giving all the old file names manually in the bat file. The old file names are extracted from the dir listing of D:\test\

You indicated an advisory message:

A duplicate file name exists, or the file cannot be found. which is displayed because the file you are attempting to rename does not exist or a renamed file already exists. Please examine the contents of d:\test\ to find out if the files are present or if they have already been renamed.

Did you Google for an answer before asking the question?


Report •

#10
April 18, 2011 at 01:58:39
Hey Thanks man it worked.

I think the script is renaming everything starting from first space.

I forgot to mention there are few files with two or more spaces before the text "SHIFT+ENTER to open the menu (new window)..aspx"

ex:

USA Div 1 SHIFT+ENTER to open the menu (new window)..aspx.html
USA Div 2 SHIFT+ENTER to open the menu (new window)..aspx.html
USA Div 3 SHIFT+ENTER to open the menu (new window)..aspx.html
UK Div 4 (PT only) SHIFT+ENTER to open the menu (new window)..aspx.html

So the bat file is renaming the first file USA.html and gives duplicate error for the second file.

I hope you understand what i am saying.

Thank you very much.


Report •

#11
April 27, 2011 at 02:37:09
Hi,

Did you tried? I keep trying but no solution.

Thanks


Report •

#12
May 18, 2011 at 09:38:33
Still using the file renamer software.

Report •


Ask Question