473,378 Members | 1,539 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

File read problem (Line by line )

Hi,
I am facing problem to read file. The file content is following :

dir1
dir2
dir3
dir4

I read the file and put all the data in an array like below
array_data[1] = dir1
array_data[2] = dir2
array_data[3] = dir3
array_data[4] = dir4

But when I want to open the all the directory by following way I can open only last directory(dir4).What can I do to open all directory?

Expand|Select|Wrap|Line Numbers
  1. for($a=0; $a<=3; $a++)
  2.      {
  3.          $file2 = array_data[$a];   
  4.          $TrackDir2 = opendir($file2);      
  5.               $j = 0;
  6.          while ($file3 = readdir($TrackDir2)) { 
  7.                if (filetype($file3) != "dir" && $file3 != "." && $file3 != ".." ) 
  8.                { 
  9.                      $fileinfo = pathinfo($file3);
  10.                      $extension = $fileinfo["extension"];
  11.  
  12.                      if($extension=="txt")
  13.                      {
  14.                              echo $txt_file_name = $file3;
  15.                          $filen2 = $fdata[$a]."/".$txt_file_name;
  16.                          $filestring = fopen($filen2,'r');
  17.                          $filecont = fread($filestring,200); 
  18.                          fclose($filestring);
  19.  
  20.                      }
  21.  
  22.                 }
  23.  
  24.          } 
  25.  
  26.          ?>    
  27.          <tr><td>
  28.          <?
  29.          echo $filecont;
  30.          ?>
  31.          </td></tr>     
  32.              <?     
  33.      }
[Please use CODE tags when posting source code. Thanks! --pbmods]

Thank to all advanced.
Jul 8 '07 #1
1 1135
mwasif
802 Expert 512MB
array_data is not a valid PHP variable name. Do you have $array_data or array_data?

You are saving the path at index 1 i.e. "array_data[1] = dir1" but in for() loop, you are fetching the data from array_data[0].

Please post the exact code here.


There may be a problem in opening a dir i.e. $TrackDir2 = opendir($file2);
Put echo before this line and see what is the value for $file2;
Jul 8 '07 #2

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

Similar topics

4
by: ESPN Lover | last post by:
Below is two snippets of code from MSDN showing how to read a file. Is one way preferred over the other and why? Thanks. using System; using System.IO; class Test { public static void...
0
by: lovecarole | last post by:
hi, i am the student who should write a program about reading wav file and do the DFT. actually i don't know how to read data of the wav song and save it into the array... if i want to read...
6
by: Thomas Kowalski | last post by:
Hi, currently I am reading a huge (about 10-100 MB) text-file line by line using fstreams and getline. I wonder whether there is a faster way to read a file line by line (with std::string line)....
9
by: flebber | last post by:
I was working at creating a simple program that would read the content of a playlist file( in this case *.k3b") and write it out . the compressed "*.k3b" file has two file and the one I was trying...
19
by: Lee Crabtree | last post by:
Is there a class in the framework that allows me read text from a file in an unbuffered manner? That is, I'd like to be able to read lines in the same manner as StreamReader.ReadLine(), but I also...
4
by: MikeJ | last post by:
make a While loop ofs = TextFileServer("somefile") string srow while (ofs=false) { srow=ofs.getRow(); Console.Writeline(srow); }
1
by: shyaminf | last post by:
hi everybody! iam facing a problem with the transfer of file using servlet programming. i have a code for uploading a file. but i'm unable to execute it using tomcat5.5 server. kindly help me how to...
15
by: patf | last post by:
Hi - experienced programmer but this is my first Python program. This URL will retrieve an excel spreadsheet containing (that day's) msci stock index returns. ...
4
by: lilyumestar | last post by:
I have project I have to do for class. We have to write 4 different .java files. Project2.java HouseGUI.java House.java HouseSorting.java I already finish House.java and I need to work on...
2
by: rka77 | last post by:
Hi, I am trying to make a Python2.6 script on a Win32 that will read all the text files stored in a directory and print only the lines containing actual data. A sample file - Set : 1 Date:...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.