How to read a directory and it's files

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bluewavessurf
    New Member
    • Oct 2010
    • 2

    #1

    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?
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    Please post the code that you have tried thus far and we will guide you to learning how to do this.

    Regards,

    Jeff

    Comment

    • bluewavessurf
      New Member
      • Oct 2010
      • 2

      #3
      Code:
      opendir MYDIR, "c:\data";
      @contents = readdir MYDIR;
      closedir MYDIR;
      
      foreach $listitem ( @contents )
      {
        print $listitem;
      }
      But I am not sure if I am going correct way and kind of lost
      Last edited by Atli; Oct 15 '10, 12:31 AM. Reason: Please use [code] tags wen posting code.

      Comment

      • Greg R

        #4
        Code:
        opendir(DIR,"c:/data") or die "Error: $!";
        @files = readdir(DIR);
        closedir(DIR);
        
        foreach $file (@files) {
           print $file;
        }

        Comment

        • RonB
          Recognized Expert Contributor
          • Jun 2009
          • 589

          #5
          How can I read the files in blocks of 64 KB?
          See:
          perldoc -f sysopen
          perldoc -f sysread

          Comment

          Working...