in reply to Re: elseif syntax error
in thread elseif syntax error

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 ...

Replies are listed 'Best First'.
Re^3: elseif syntax error
by gmargo (Hermit) on Oct 27, 2009 at 16:07 UTC

    You don't need recursion, because the "find" function is traversing the directory structure for you.

    The errors you see are due to renaming of a directory before it is finished being used. Try "finddepth" instead of "find". The "finddepth" routine will process a directory's contents before the directory itself.