By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,773 Members | 1,724 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,773 IT Pros & Developers. It's quick & easy.

List directory contents

P: 4
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
Share this Question
Share on Google+
6 Replies


P: 65
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 100+
P: 410
Try this:
Expand|Select|Wrap|Line Numbers
  1. @files = <"$dir*">; # $dir* within quotes
  2.  
- Nithin
Oct 14 '08 #3

P: 4
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

P: 65
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

P: 65
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

P: 4
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.