in reply to Processing All Files in a Directory Recursively under Windows OS

Works for me:

X:\>perl -MFile::Find -le "sub process_file{print $File::Find::name if + -f };find (\&process_file,'test with whitespace')" test with whitespace/a file.txt
Q:\>dir "test with whitespace" Datenträger in Laufwerk Q: ist homes_xxxxxxxx$ Volumeseriennummer: DEAD-BEEF Verzeichnis von Q:\test with whitespace 17.09.2007 11:12 <DIR> . 17.09.2007 10:10 <DIR> .. 17.09.2007 11:12 0 a file.txt

Maybe you can show us some code, the input and the output.

Replies are listed 'Best First'.
Re^2: Processing All Files in a Directory Recursively under Windows OS
by azaria (Beadle) on Sep 17, 2007 at 09:34 UTC
    First thanks for your reply, if i run from the command line
    X:\>perl -MFile::Find -le "sub process_file{print $File::Find::name if + -f };find (\&process_file,'test with whitespace')"
    it works perfectly, the problems came when the I am using it in a file with variables, means :
    use File::Find; print "Enter your root directory\n"; $root = <STDIN> ; sub process_file{ print $File::Find::name if -f ; } find (\&process_file,$root);
    %> a.pl Enter your root directory: D:\DBS %> Can't state D:\DBS

    Any idea what is the reason for this failure ?

    Thanks in advance
    Azaria

    20070918 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips

      Please use proper HTML formatting and preview your node before you post it.

      Your variable $root is not what you think it is. Print it out like this:

      my $root = "Hello world"; print "Root is >>$root<<\n";

      In your case, when you read $root from STDIN it has a newline appended to it. You should remove that by using the chomp function:

      chomp $root;