Computing.Net > Forums > Programming > rename multiple file whit batch fil

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

rename multiple file whit batch fil

Reply to Message Icon

Name: lisa_enk
Date: January 3, 2004 at 09:41:27 Pacific
OS: win xp
CPU/Ram: atlhon xp , 512
Comment:

hi all
I want to create a batch file for rename multiple files , or rename only a part of file name for examples:
original:
01-one.txt
02-five.txt
rename in:
one.txt
five.txt
.
I have many files
thanks all




Sponsored Link
Ads by Google

Response Number 1
Name: dtech10
Date: January 4, 2004 at 07:23:14 Pacific
Reply:

Hi lisa_enk
Are all the files in one directory and are they all numbered the same with the number than an hyphen and the the rest of the name you wish to rename them to.


0

Response Number 2
Name: lisa_enk
Date: January 4, 2004 at 10:53:55 Pacific
Reply:

yes,
all file are un the same directory and they are numbered the same whit progressive number .
And all five have hyphen .
the general five is :

xx-filename.txt
when xx is progressive number.
and I want to rename in:
filename.txt

other file have this form :
xx-subtitle-filename.txt
and I want to rename in:
filename.txt

thanks


0

Response Number 3
Name: dtech10
Date: January 4, 2004 at 13:36:46 Pacific
Reply:

Hi Lisa
I'll see what I can come up with.


0

Response Number 4
Name: dtech10
Date: January 4, 2004 at 14:45:29 Pacific
Reply:

Hi Lisa
Note you can only run this once because some of your txt files have two hyphens and the hyphen between %%a-%%b would cause an error on the second run

@echo off
dir /b *.txt >files.tmp
for /f "tokens=1* delims=-" %%a in (files.tmp) do ren %%a-%%b %%b >nul



0

Response Number 5
Name: dtech10
Date: January 4, 2004 at 15:05:38 Pacific
Reply:

Hi Lisa
I realised you did'nt want the second hyphen so this will work without error.

@echo off
dir /b *.txt | find "-" > files.tmp
for /f "tokens=1* delims=-" %%a in (files.tmp) do ren %%a-%%b %%b
dir /b *.txt | find "-" > files.tmp
for /f "tokens=1* delims=-" %%a in (files.tmp) do ren %%a-%%b %%b



0

Related Posts

See More



Response Number 6
Name: SN
Date: January 4, 2004 at 21:00:03 Pacific
Reply:

Also, feel free to check out A.F.5 rename your files, available for free at download.com.

-SN


0

Response Number 7
Name: lisa_enk
Date: January 5, 2004 at 01:07:30 Pacific
Reply:

thanks dtech10 the 2 batch file work fine
but now I have some problem
whit this file :

xx - filename.txt

or

xx - subtitle - filename.txt


I think that is a simple modification of the previous ones, but I'm not be able. :-(

thanks also to SN


0

Response Number 8
Name: dtech10
Date: January 5, 2004 at 05:13:44 Pacific
Reply:

Hi Lisa
Do you mean there are spaces before and after the hyphen in your filenames.


0

Response Number 9
Name: lisa_enk
Date: January 5, 2004 at 06:18:33 Pacific
Reply:

Yes dtech10,
there are space before and after the hyphen
in the file name.


0

Response Number 10
Name: dtech10
Date: January 5, 2004 at 07:17:46 Pacific
Reply:

Hi Lisa
Use this it contains the first batch file code and the extra code to delete filenames containing " - "


@echo off
rem Rename files with extra spaces in then
dir /b *.txt | find " - " > files.tmp
for /f "tokens=1* delims=- " %%a in (files.tmp) do ren "%%a - %%b" "%%b"
dir /b *.txt | find " - " > files.tmp
for /f "tokens=1* delims=- " %%a in (files.tmp) do ren "%%a - %%b" "%%b"

rem Rename without extra spaces in them
dir /b *.txt | find "-" > files.tmp
for /f "tokens=1* delims=-" %%a in (files.tmp) do ren %%a-%%b %%b
dir /b *.txt | find "-" > files.tmp
for /f "tokens=1* delims=-" %%a in (files.tmp) do ren %%a-%%b %%b

rem Tidyup
del files.tmp


0

Response Number 11
Name: FishMonger
Date: January 6, 2004 at 07:36:07 Pacific
Reply:

Here's a Perl script that does exactly what you asked for.

#!perl -w
while (<*>) {
if (/([^\s-]+)$/) {rename $_, $1;}
}


0

Response Number 12
Name: FishMonger
Date: January 6, 2004 at 07:55:44 Pacific
Reply:

Actually, we may want to change the regex to be a little more expicit.

if (/^\d+[\s-]+(\w+\.txt)$/) {rename $_, $1;}


0

Response Number 13
Name: FishMonger
Date: January 6, 2004 at 08:07:28 Pacific
Reply:

While I'm at it, this can be done as 1 single line at the command prompt instead of a script, like this:

perl -e "while(<*>){if (/^\d+[\s-]+(\w+\.txt)$/) {rename $_, $1;}}"


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: rename multiple file whit batch fil

Ren multiple files in DOS www.computing.net/answers/programming/ren-multiple-files-in-dos/19273.html

Batch file renaming www.computing.net/answers/programming/batch-file-renaming/18553.html

Batch file to rename .tif files www.computing.net/answers/programming/batch-file-to-rename-tif-files/14681.html