Home > Archive > PERL Programming > October 2005 > Renaming files across multiple directories
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Renaming files across multiple directories
|
|
| DieSpammersDie 2005-10-24, 3:55 am |
| 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.
| |
| baygross@gmail.com 2005-10-24, 3:55 am |
| 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
| |
| Al Klein 2005-10-24, 3:55 am |
| On Sun, 23 Oct 2005 23:40:42 -0400 (EDT), "DieSpammersDie"
<DieSpammersDie-no-spam@antigone.cotse.net.invalid> said in
alt.comp.freeware:
>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
| |
| Joe Smith 2005-10-24, 3:55 am |
| DieSpammersDie wrote:
> 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
| |
|
| DieSpammersDie wrote:
> How can I accomplish this? Thanks for the help.
I'm sure Siren can handle this.
http://www.scarabee-software.net/
--
Anne
Metermaids eat their young.
|
|
|
|
|