Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Findfirst/findnext 2

Status
Not open for further replies.

realm174

Programmer
Jan 3, 2002
154
CA
Howdy people!

Is there a way to do a findfirst/findnext in FPD26a? I need to find every file "*.usr" (they're just plain text files) and read the content on each. Problem is, they can be any name, not a set of specific filenames. So I was hoping something along the lines of:

...
findfirst("*.usr",isthere)
do while isthere
do readcontent
findnext(isthere)
enddo

Any idea?

Thanks!!

Realm174
 
To get the file list, you might try using the ADIR() function. Look at the Foxpro Help file for ADIR()

Something like:
DIMENSION DirArr(1)
=ADIR(DirArr, "C:\MyDir\*.USR")
m.nLenArr = ALEN(DirArr,1)
IF m.nLenArr > 1
< you have a list of files >
FOR i = 1 TO m.nLenArr
m.cFileName = DirArr(i,1)
< do whatever >
ENDFOR
ELSE
< none found >
ENDIF

As to &quot;reading&quot; a text file, you will need to use Fox low-level file commands (FOPEN, FPUTS, FGETS, FCLOSE, etc.) to Open and then &quot;Read&quot; character string buffers; examining them for whatever you are looking to find.

Good Luck,


JRB-Bldr
VisionQuest Consulting
Business Analyst & CIO Consulting Services
CIOServices@yahoo.com
 
Realm174,
sys(2000..) may process unlimited number of files.
fndfile=sys(2000,&quot;*.usr&quot;)
do while len(fndfile)>0
do readcontent
fndfile=sys(2000,&quot;*.usr&quot;,1)
enddo
Tesar

 
jrbbldr: Thanks for the help!! Talking about which, maybe I should rely on the help file more than I rely on the book I have... Turns out &quot;ADIR&quot; is not in the book, but it is in the help file. As for reading the files themselves, that's not a problem, I already knew how to do that.. :)

tesar: Thank you also! This will actually work better in this case, seeing as that directory can have an unlimited number of files to go through. So if I'm not limited by the size of an array, that's even better. Again, the book I have was not clear on that. It does mention sys(2000) to find the first file, but does not mention the ,1 to get the next one, which is exactly the kind of function I'm looking for.

Thanks to you both! This place will never cease to amaze me... Each time I posted a question on here, I had more than one answer in less than 24 hours... That's what communities are all about!!

Thanks guys!!

Cheers,

realm174
 
If you only want to read the file, here is a simple way:

function readcontent
parameter yourfile
define window showfile from 0,0 to 24,79;
system shadow zoom close float
modify file yourfile noedit window showfile
release window showfile

This function should be called from one of the procedures posted above.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top