Re: reading directories using perl in windows
On Sun, 13 Mar 2016 09:48:20 -0500 Mike Flannigan <mikef...@att.net> wrote: > > FYI, there is no error. If the directory > path has no spaces it works fine, if the directory > path has spaces it prints the path up to the 1st space > and just goes back to a cursor line. > > > Mike Yup. The default glob() function s based on the C-shell and spaces are separators. If your file names have spaces, use the BSD glob. This will replace glob() with one that allows spaces in the file names. use File::Glob qw( :bsd_glob ); > > > On 3/6/2016 5:04 AM, beginners-digest-h...@perl.org wrote: > > Subject: > > Re: reading directories using perl in windows > > From: > > Akshay Mohit <akshaymohit2...@gmail.com> > > Date: > > 3/1/2016 4:49 AM > > > > To: > > Arghya Das <arghya0...@gmail.com> > > CC: > > Perl Beginners <beginners@perl.org> > > > > > > Could you please send the exact error which you are getting as I > > Copy/Pasted the exact code which you had given and it is working > > properly for me. I have only given the directory which is present > > in my system. > > > > use strict; > > use warnings; > > > > my $dir = "C:/Python_Exercise/*"; > > my @files = glob( $dir ); > > > > foreach (@files ){ > >print $_ . "\n"; > > } > -- Don't stop where the ink does. Shawn -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: reading directories using perl in windows
FYI, there is no error. If the directory path has no spaces it works fine, if the directory path has spaces it prints the path up to the 1st space and just goes back to a cursor line. Mike On 3/6/2016 5:04 AM, beginners-digest-h...@perl.org wrote: Subject: Re: reading directories using perl in windows From: Akshay Mohit <akshaymohit2...@gmail.com> Date: 3/1/2016 4:49 AM To: Arghya Das <arghya0...@gmail.com> CC: Perl Beginners <beginners@perl.org> Could you please send the exact error which you are getting as I Copy/Pasted the exact code which you had given and it is working properly for me. I have only given the directory which is present in my system. use strict; use warnings; my $dir = "C:/Python_Exercise/*"; my @files = glob( $dir ); foreach (@files ){ print $_ . "\n"; }
Re: reading directories using perl in windows
On Tue, 1 Mar 2016 15:53:15 +0530 Arghya Daswrote: > use warnings; > > $dir = "c:/folder/*";my @files = glob( $dir ); > foreach (@files ){ >print $_ . "\n";} > > > i am trying to read windows directory using above code but it gives > errors in recognising tthe directory path. please help. Does the directory path have spaces in its names? If so, glob() does not work correctly. Use the BSD glob() instead. use File::Glob qw( :bsd_glob ); See `perldoc File::Glob` for details. http://perldoc.perl.org/File/Glob.html -- Don't stop where the ink does. Shawn -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: reading directories using perl in windows
On 1 March 2016 at 23:23, Arghya Daswrote: > $dir = "c:/folder/*"; > my @files = glob( $dir ); > > foreach (@files ){ >print $_ . "\n"; > } Personally, I would have used either Path::Tiny, or at least, readdir() here. There's far few places that can lead to strange bugs and security holes with that. With readdir: my $base = "C:/folder"; my $dir = opendir($base ); while ( my $entry = readdir( $dir ) ) { next if $entry =~ /\A..?\z/ # skip cwd and updir dirs printf "%s\n", $entry; } With Path::Tiny: use Path::Tiny qw( path ); for my $child ( path( "C:/folder/" )->children() ) { print $child . "\n"; } -- Kent KENTNL - https://metacpan.org/author/KENTNL -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: reading directories using perl in windows
Could you please send the exact error which you are getting as I Copy/Pasted the exact code which you had given and it is working properly for me. I have only given the directory which is present in my system. use strict; use warnings; my $dir = "C:/Python_Exercise/*"; my @files = glob( $dir ); foreach (@files ){ print $_ . "\n"; } o/p === C:\Users\makshay\Documents>perl test.pl C:/Python_Exercise/__pycache__ C:/Python_Exercise/emp.db C:/Python_Exercise/emp1.db C:/Python_Exercise/exception_handling.py C:/Python_Exercise/Exercise1.py C:/Python_Exercise/test.db C:/Python_Exercise/Test.py C:/Python_Exercise/test.txt C:/Python_Exercise/test_copy.txt C:\Users\makshay\Documents> -Akshay On Tue, Mar 1, 2016 at 3:53 PM, Arghya Daswrote: > use warnings; > > $dir = "c:/folder/*";my @files = glob( $dir ); > foreach (@files ){ >print $_ . "\n";} > > > i am trying to read windows directory using above code but it gives errors in > recognising tthe directory path. please help. > > >
Re: reading directories using perl in windows
Try using readdir http://perldoc.perl.org/functions/readdir.html On Tue, Mar 1, 2016, 5:24 AM Arghya Das> wrote: use warnings; $dir = "c:/folder/*"; my @files = glob( $dir ); foreach (@files ){ print $_ . "\n"; } i am trying to read windows directory using above code but it gives errors in recognising tthe directory path. please help.
reading directories using perl in windows
use warnings; $dir = "c:/folder/*";my @files = glob( $dir ); foreach (@files ){ print $_ . "\n";} i am trying to read windows directory using above code but it gives errors in recognising tthe directory path. please help.