wheakory Posted January 13, 2009 Share Posted January 13, 2009 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 More sharing options...
trq Posted January 13, 2009 Share Posted January 13, 2009 This php script would be ran in cron or command line, no web interaction. Why use php at all then? Link to comment https://forums.phpfreaks.com/topic/140594-read-directory-files-then-open-each-one/#findComment-735771 Share on other sites More sharing options...
dawsba Posted January 13, 2009 Share Posted January 13, 2009 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);} } } Link to comment https://forums.phpfreaks.com/topic/140594-read-directory-files-then-open-each-one/#findComment-735925 Share on other sites More sharing options...
wheakory Posted January 14, 2009 Author Share Posted January 14, 2009 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. Link to comment https://forums.phpfreaks.com/topic/140594-read-directory-files-then-open-each-one/#findComment-737113 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.