Renaming files across multiple directories

G

Guest

I have a file I download everyday, let's call it "output.txt." The file
"output.txt" is saved in a directory by date, for example 10012005 (for Oct.
1, 2005). I have a years worth of output files in my c:\ drive. Now I have
to rename each output file so that I can copy all of the output to a single
directory. It's a nightmare to do manually. I really don't care what the
files are named as long as each file gets a unique name. Imaging this:

C:\01012005
C:\01022005
C:\01032005
C:\01042005
.. . .

Now, each of those directories has a file in it called "output.txt." I want
to get everyone of those "output.txt" and copy it to a single directory
(call it c:\renoutput) and each output will have a unique name. So when I
do a "dir" of C:\RENOUTPUT is looks like:

output1.txt
output2.txt
output3.txt
output4.txt
.. . .

How can I accomplish this? Thanks for the help.
 
B

baygross

put this in a batch file... eg: myfile.bat
and run it from your main directory
***************************************************
setlocal enabledelayedexpansion
set num=1
for /f "tokens=*" %%a in ('dir /s /b *.txt') do (
copy "%%a" "c:\renoutput\output!num!.txt"
set /a num+=1
)
******************************
untested, but should do what you want in XP
-BG
 
A

Al Klein

I have a file I download everyday, let's call it "output.txt." The file
"output.txt" is saved in a directory by date, for example 10012005 (for Oct.
1, 2005). I have a years worth of output files in my c:\ drive. Now I have
to rename each output file so that I can copy all of the output to a single
directory. It's a nightmare to do manually. I really don't care what the
files are named as long as each file gets a unique name. Imaging this:

C:\01012005
C:\01022005
C:\01032005
C:\01042005
. . .

Now, each of those directories has a file in it called "output.txt." I want
to get everyone of those "output.txt" and copy it to a single directory
(call it c:\renoutput) and each output will have a unique name. So when I
do a "dir" of C:\RENOUTPUT is looks like:

output1.txt
output2.txt
output3.txt
output4.txt
. . .

How can I accomplish this? Thanks for the help.
With a program you can download? Or with something you can write? It
should be easy to write a program that starts at the root of those
directories, goes into each of them and names the files
<directoryname>_output.txt, or maybe even
...\<directoryname>_output.txt
 
D

Demetris

Using a GUI tool, Rename Master (http://www.joejoesoft.com/rm.php --
examples: http://www.joejoesoft.com/rm-help.php):

+ Select the directories
+ Click on "Recursive Scan" (two buttons right to "File Menu")
+ In "Add To", under "Name", tick "end"
+ Click the blue arrow to open the "Metavariables" window
+ Select "Current Folder"
+ If the preview is ok, click "Rename"

To copy the renamed files, search for "output????????.txt" (8 question
marks for the 8 characters added to each filename), and copy the files
to the new place.

Alternatively, RM allows you to rename and *move* (not copy) files in
one go. After step 2 above, insert:

+ In "Add To", under "Name", tick "insert"
+ Put this in the box: "..\New\"

This will rename the files and move them to a directory named "New", at
the same level as your current directories.

RM can save such actions in scripts, which can also be used from the
command line.

Also, instead of the containing directory, you can add the creation or
modification date (or both) in ISO 8601 format (yyyy-mm-dd), assuming
files have different dates. I find this is better for sorting.

Greetings,
Demetris
 
J

Joe Smith

DieSpammersDie said:
C:\01012005
C:\01022005
C:\01032005
C:\01042005
. . .

Now, each of those directories has a file in it called "output.txt." I want
to get everyone of those "output.txt" and copy it to a single directory

Untested:
C:\> perl -e "for(@ARGV){($n=$_)=/s(\d+)(.)output.txt/newdir$2$1.txt/;
rename $_,$n or warn 'rename(',$n,')',$!}"

-Joe
 

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