Renaming ordered files based on a txt file

July 13, 2009 at 09:09:09
Specs: Windows 7
I have a program that makes a master list file9( msx00 ) with each persons name in order in it. Then it creats a file for each person but its named msx01.doc, msx02.doc, msx03.doc etc. instead of the name of the person. I then have to go in and rename all the files. How would I be able to use a batch program to use the first text file to rename the other files correctly?

an example of the first text file is:

completed processing
bla bla
(empty line)

john doe
jane doe
jack
etc.

Any help would be appreciated as this takes up more time than it should.


See More: Renaming ordered files based on a txt file

Report •


#1
July 13, 2009 at 09:18:20
First, is there just one blank line?

And do the names start immediately after it?

Are the file names strictly msxXX.doc or do they run to 3 or more digits?


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#2
July 13, 2009 at 10:28:46
Unfortunately the real files are at work and I dont have acess to them. But I have no problem deleting a line with nothing in it if that makes it easier. Just as long as I dont have to keep manually renaming 50+ files manually I dont mind some leg work. The names start directly after the blank line though. Also the actual name of the files have a 5 digit name plus the numbering sequence (msxrtXX.doc) or something like that. I figured I could do some tailoring when I get to work tommorow. Thank you for your help!

Report •

#3
July 13, 2009 at 15:18:18
Once you take out the 'header' lines, something like this:

==========================
@echo off & setLocal EnableDelayedExpansion

for /f "tokens=1* delims=[]" %%a in ('find /v /n "" ^< myfile') do (
if %%a lss 10 (
echo ren msxrt0%%a.doc "%%b.doc"
) else (
echo ren msxrt%%a.doc "%%b.doc"
)
)


Report •

Related Solutions

#4
July 13, 2009 at 16:35:30
Thanks for your help so far. But I am getting a syntax error on the batch file. I checked about 7 times trying to see if i typed it in wrong, and then tried it as one line and again with the spacing you replied with. I made the test files from the command prompt making sure they were only msxrt0.doc and so on.

The test files basically went like this:

msxrt0.doc
(this is the text in file without the header)
amy
john
mark
paul

msxrt1.doc
asdf

msxrt2.doc
asdf

msxrt3.doc
asdf

msxrt4.doc
asdf

Thanks again, you really are awesome.


Report •

#5
July 13, 2009 at 23:12:03
I almost always paste instead of retyping. Saves errors.

Next, you should run it at a prompt; not by clicking.

As written above it doesn't rename, but simply previews what's to be done.

Here's how it should look.

=================================

@echo off & setLocal EnableDelayedExpansion

for /f "tokens=1* delims=[]" %%a in ('find /v /n "" ^< myfile') do (
if %%a lss 10 (
ren msxrt0%%a.doc "%%b.doc"
) else (
ren msxrt%%a.doc "%%b.doc"
)
)


=====================================
If at first you don't succeed, you're about average.

M2


Report •


Ask Question