Jump to content

Read directory files then open each one


wheakory

Recommended Posts

I need to read a linux directory listing and then open those files and read each one's content.  Below is how I did it in PERL and I would like to use similar code to do in PHP.  Any examples?  These Files need to be stored in two dimensional arrays too.  This script is embedded with Zend Google data code creating Gmail accounts.

 

This php script would be ran in cron or command line, no web interaction.

 

 

        open(FILES,"ls -1 $acctpath/* 2>/dev/null |");

 

        #change made to log transactions, rather than, keep files on the system

        while(<FILES>){

        chop;

                $filename = $_;

 

# New transaction file naming convention uses a four character c

ode extention to indicate the transaction type.

# The first two letters of the extention denote the system and t

he next two letters denote the operation to be performed.

# The system codes are as follows:  CW (Cwis), RA (Remote Access

), M1 (Mail Server 1 -> additional mail systems can be

                $tmpString = substr($filename, -4, 2);

                      #groupchange

                        if (($tmpString eq "cw") || ($tmpString eq "ra") || ($tmpString

eq "rd") || ($tmpString eq "m1") || ($tmpString eq "m2") || ($tmpString eq "ex") || ($tm

pString eq "gp")) {

                                ($junk,$junk,$junk,$junk,$junk,$junk,$junk,$size,@junk)

= stat($filename);

                                $files2{$filename} = $size;

                                $count2++;

                        }

                }

                close(FILES);

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/140594-read-directory-files-then-open-each-one/
Share on other sites

This might get you started

 

$targetdir = getcwd()."/";

$array = array();

$directory = opendir($targetdir);

while($filename2 = readdir($directory))

{

  if(strlen($filename2) > 2)

  {

    if(is_file($filename2)){array_push($array[$directory], $filename2);}

  }

}

This php script would be ran in cron or command line, no web interaction.

 

Why use php at all then?

 

Perl doesn't work with Google's Zend Framework to create automated Email Google Accounts for our University.  That's what this code will be used for.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.