471,887 Members | 1,434 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,887 software developers and data experts.

How to read a directory and it's files

I want to implement a Perl Program that takes a directory path, ex (d:\programs) as an INPUT and this directory could have multiple files for this program let’s say 5 files (doc1, doc2, doc3, doc4, and doc5). This program should print the average time to open and read all these five files into OUTPUT. How can I read the files in blocks of 64 KB?
Oct 14 '10 #1
4 1732
numberwhun
3,503 Expert Mod 2GB
Please post the code that you have tried thus far and we will guide you to learning how to do this.

Regards,

Jeff
Oct 14 '10 #2
Expand|Select|Wrap|Line Numbers
  1. opendir MYDIR, "c:\data";
  2. @contents = readdir MYDIR;
  3. closedir MYDIR;
  4.  
  5. foreach $listitem ( @contents )
  6. {
  7.   print $listitem;
  8. }
But I am not sure if I am going correct way and kind of lost
Oct 14 '10 #3
Expand|Select|Wrap|Line Numbers
  1. opendir(DIR,"c:/data") or die "Error: $!";
  2. @files = readdir(DIR);
  3. closedir(DIR);
  4.  
  5. foreach $file (@files) {
  6.    print $file;
  7. }
  8.  
Oct 16 '10 #4
RonB
589 Expert Mod 512MB
How can I read the files in blocks of 64 KB?
See:
perldoc -f sysopen
perldoc -f sysread
Oct 18 '10 #5

Post your reply

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

Similar topics

8 posts views Thread by Gurk | last post: by
3 posts views Thread by Simon Wigzell | last post: by
2 posts views Thread by Andrea Bauer | last post: by
6 posts views Thread by fabrizio | last post: by
reply views Thread by YellowAndGreen | last post: by
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.