Can't cd to (./test/) test test test test: No such file or directory
at e:\path\myfiles\perl\filename_spaces2.pl line 7
The code is fine it is not completely "recursive" someone of you got some hint how to go down in every subdirectory?
If i start it a second time it is working ...
On first attempt the directory tree is (i got several space containing files below E:\temp:
#Perl should find spaces and replace them with "-"
#
use warnings;
use File::Copy;
use File::Find;
find(\&rename_txts, ".");
#Pfade ... find(\&rename_txts, "./txt2/");
sub rename_txts {
if (!/^\.+$/) {
my $new_name = $_;
$new_name =~ y/ /-/;
print "$File::Find::name to $new_name\n";
print "$_ \n";
move $_, $new_name;
}
}
The result is:
"E:\temp\test\test test test test"\Files with spaces ...
2nd attempt:
"E:\temp\test\test-test-test-test"Files-with-spaces...
so the 2nd (or depending on the number of subdirectories run is ok)
Thx for all your help so far
btw:
The purpose is to rename all the files on a network drive to proper names without spaces ...
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.