You don't show us any code, so I won't show any code either:
- rename for renaming files
- perlre for replacing one part of text with another part of text, also perlop for the s/// operator
- glob respectively File::Glob for bsd_glob
Another approach, which I often prefer, is to output shell commands via print, which I then, after close inspection, pipe into another shell.
| [reply] [d/l] [select] |
There's a rename (sometimes also called prename) program that's shipped with Perl. You can use it for this task:
rename "s/\.xml$/.txt" *.xml
| [reply] [d/l] [select] |
And if you don't have it, it is on CPAN.
| [reply] |
If you happen to be in a bash shell, then you hardly need to invoke Perl, since you have builtins at your disposal..
for N in *.xml; do
mv $N ${N/%xml/txt}
done
but if you must do that in Perl you can
perl -e 'qx!for N in *.xml\; do mv \$N \${N/%xml/txt}\; done!;'
:)
Note, though, TMTOWTDI: site:perlmonks.org rename files directory
Also this: Re: What one-liners do people actually use? is awesome.
correction: /%xml/ not /xml/ good catch suhailck!
| [reply] [d/l] [select] |
Your bash script replaces filename like "xml.xml" to "txt.xml". I think you need to change the script as follows inorder to work as expected,
mv $N ${N/%xml/txt}
| [reply] [d/l] |
There is also the 'mmv' command, if you are on linux
| [reply] |