Pattern matching

H

Howard Brazee

What free or inexpensive tool can be used with Windows to rename a bunch of
files such as:

04/23/2004 09:36a 0 file 09 of 40 report09.txt
04/23/2004 09:36a 0 file 09 of 40 My file09.txt
04/23/2004 09:36a 0 file 10 of 40 My file010.txt


to report09.txt, My file09.txt, and My file010.txt?

I've been working at creating Ultra-Edit macros to create .bat files to do this,
but would like something more direct.

Also, what .bat file commands will do what I want?
 
N

Nathan Widmyer

Howard said:
What free or inexpensive tool can be used with Windows to rename a bunch of
files such as:

04/23/2004 09:36a 0 file 09 of 40 report09.txt
04/23/2004 09:36a 0 file 09 of 40 My file09.txt
04/23/2004 09:36a 0 file 10 of 40 My file010.txt


to report09.txt, My file09.txt, and My file010.txt?

I've been working at creating Ultra-Edit macros to create .bat files to do this,
but would like something more direct.

Also, what .bat file commands will do what I want?
If you have access to Linux with Perl, you can write a pretty small perl
script to do that using regular expressions. If you don't have it
installed, you can run Knoppix and boot your computer into Linux off of
the CD without destroying Windows. You can access NTFS or FAT32 volumes
from it, run the script and get your result. I'm not that good at
regular expressions, so unfortunately my help ends here, sorry.

Good luck, Nathan.
 
D

David Candy

If "My File (1).txt" is ok, select all, right click first one, Rename - Enter "My File.txt"

The for command is what one would use.

for %%A IN (*.txt) Do OtherBatFile %%A

In the other bat file you use a second for loop to parse %1

Something like this
set FName=%~n1%~x1
FOR /F "usebackq tokens=1,2,3,4* delims=,. " %%i in ('%Fname%') do echo %%i and %%j

except call a third batch that numbers

like these two (from another answer to another similar problem)

Create two batch Files

Set X=0
for %%A IN (*.*) Do Call RenFile %%A


and call the second RenFile
set /a x=x+1
ren "%1" "%~n1%x%%~x1"

This will a an incrementing number to the end of the file name for all files in the folder it's run in.
 
H

Howard Brazee

04/23/2004 09:36a 0 file 09 of 40 report09.txt
04/23/2004 09:36a 0 file 09 of 40 My file09.txt
04/23/2004 09:36a 0 file 10 of 40 My file010.txt


to report09.txt, My file09.txt, and My file010.txt?


Also, what .bat file commands will do what I want?

One trouble with putting these in a batch file is that the following works:
dir *My?file010.txt
but I don't see any other way of finding "My file" using wild cards.

If I create a batch file, I need to account for every space.

So some kind of command shell probably would be easier than trying to figure out
how to write a batch file.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top