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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping through text file 2

Status
Not open for further replies.

coldan

Programmer
Oct 19, 2008
98
AU
In attempting to solve the 'Unable to delete' problem in a previous message I am writing a txt file of the 'saved' (modified)image filenames so that they can be copied back after the Form with the grid is closed.


I create a text file instead of doing the delete.

Thus I have a text file with a certain ( unknown) number of lines in it.

A typical line is 3:19:58 PM | C:\USERS\COLIN\DESKTOP\helen gkids.jpg
I want to loop through line by line and do an operation on the filename after the |. I already know where the newly created files with the new exif values are.

Is there a function to, say, create an array from the text file which I can then loop through and replace the original image file with the new one?

OR

is there a better way?


Thanks

Coldan
 
Coldan,

Is there a function to, say, create an array from the text file ...

Yes. ALINES().

... which I can then loop through and replace the original image file with the new one?

Something like this:

Code:
FOR lnI = 1 TO ALEN(MyArray)
  lcLine = MyArray(lnI)
  lcLine = STREXTRACT(lcLine, "", "|", 2) + lcNewFileName
  MyArray(lnI) = lcLine
ENDFOR

This is off the top of my head, and not tested, but it should give you the general idea.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Of course there are such functions like alines(), at(), substr(),strextract(), ... and many ways to do that in VFP.

ie:
Code:
local ix, lcFileName
local array laFiles[1]
for ix = 1 to alines(laFiles, FileToStr('MyText.txt'))
  lcFileName = Ltrim(Substr(laFiles[m.ix], at('|', laFiles[m.ix])+1))
  * Do whatever with the file
endfor

However an easier one would be to work with a cursor:
Code:
create cursor fileNames (dummyData c(50), fileName c(254))
append from ('myText.txt') ;
 delimited with "" with character '|'
update fileNames SET fileName = LTRIM(fileName)

And you could directly save to a cursor instead of a text file in the first place.



Cetin Basoz
MS Foxpro MVP, MCP
 
"I create a text file..."

The others above have given you some good advice, but my question would be - Why are you doing this in a "Text File"?

Why aren't you using a data table?

If this were a situation where you needed a temporary data storage location, you could always create a data table and then delete it when no longer needed.

And if this were a situation where you needed a more permanent data storage location, a data table would be a better choice since working with the content data would be MUCH easier.

Good Luck,
JRB-Bldr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top