467,179 Members | 1,285 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,179 developers. It's quick & easy.

List directory contents

Hi all,

I've searched the net for a while, and tried a lot of things. The script I wrote prints the contents of a directory. It works fine for a directory with no space in it, but with a space it doens't. I tried putting in qoutation marks, but that doesn't help. Anyone some ideas?

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2. my $dir = 'c:\Documents and Settings\\\';
  3. @files = <$dir*>;
  4. foreach $file (@files) {
  5. if (-d $file) {
  6.   print "$file [DIR]\n";
  7.   } else {
  8.   my $filesize = -s $file;
  9.   print "$file [$filesize]\n";
  10.   }
Oct 14 '08 #1
  • viewed: 3167
Share:
6 Replies
Hi there,

Are you talking abt the directory name having space in it is it ???

like this one :
Expand|Select|Wrap|Line Numbers
  1. dir name: xyz abc
  2.  

Regards,
Vijayarl
Oct 14 '08 #2
nithinpes
Expert 256MB
Try this:
Expand|Select|Wrap|Line Numbers
  1. @files = <"$dir*">; # $dir* within quotes
  2.  
- Nithin
Oct 14 '08 #3
Vijayarl: Yes

Try this:
Expand|Select|Wrap|Line Numbers
  1. @files = <"$dir*">; # $dir* within quotes
  2.  
- Nithin
Nope, doesnt't work. There's no output at all now
Oct 14 '08 #4
try this :

Expand|Select|Wrap|Line Numbers
  1. my $dir = 'C:/Performance_svap/INPUT FILES'; ### give your directory path here
  2. opendir(DIR, $dir) || die "can't opendir $dir: $! \n"; 
  3. @tmparray = readdir(DIR);
  4. print "@tmparray \n";
  5.  
Regards,
Vijayarl
Oct 14 '08 #5
hi,

and even if you want can go through this post :

http://bytes.com/forum/thread844454.html

jeff has clearly explained how script works & even it avoid reading . & .. (dot & dot dot) contents from the directory.

have a try !!!

Regards,
Vijayarl
Oct 14 '08 #6
Yes!!! U made my day, thanks a lot!
Oct 14 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Harold Crump | last post: by
3 posts views Thread by Nick | last post: by
14 posts views Thread by kpp9c | last post: by
4 posts views Thread by thoseion@gmail.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.