home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / perl / 4882 < prev    next >
Encoding:
Text File  |  1992-07-22  |  778 b   |  33 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!noc.near.net!chpc.chpc.org!shishir
  3. From: shishir@chpcchpc.org (Shishir Gundavaram)
  4. Subject: # of files in directory
  5. Message-ID: <1992Jul22.182940.1248@chpc.org>
  6. Keywords: Files, Perl, Directory, ls
  7. Sender: shishir@chpc (Shishir Gundavaram)
  8. Nntp-Posting-Host: chpc.chpc.org
  9. Organization: Center For High Perf. Computing of WPI; Marlboro Ma
  10. Date: Wed, 22 Jul 1992 18:29:40 GMT
  11. Lines: 20
  12.  
  13. Hi,
  14.  
  15. Can anyone please tell me if there an easy way in Perl to determine
  16. the number of files in a particular directory.
  17.  
  18. One way I can think of to do this is:
  19.  
  20.     opendir (FILE, "/usr/bin");
  21.     @some_array = grep (!/^\./, readdir (FILE));
  22.     $number = $#some_array + 1;
  23.     print "There are $number of files!";
  24.  
  25. But this is messy. 
  26.  
  27.  
  28. Thanks,
  29.  
  30. --Shishir
  31.  
  32.  
  33.