Page 1 of 1

Read txt Files and populate a Table

Posted: Thu Nov 19, 2015 9:35 pm
by ChrisM
Hi,

I'm looking for some help, and hoping someone here will have a clue on where to start with this.

what I'm trying to do is read separate text files that are in over 200 folders on a UNC patch, its the same filename in each folder IE:-

\\server01\TEST\Folder1\test.txt
\\server01\TEST\Folder2\test.txt
\\server01\TEST\Folder3\test.txt
Etc

The first line of text is a name, the second is a date. I'm looking to get livecode to search for these files, the put the name into 1 column and the date into the next - then sort into date order.

anyone done something similar or know how to do this?

Thanks in advance

Re: Read txt Files and populate a Table

Posted: Thu Nov 19, 2015 9:41 pm
by Simon
Hi Chris,
Here is your start;
http://lessons.livecode.com/m/4603/l/44 ... ng-to-file

Simon

Re: Read txt Files and populate a Table

Posted: Thu Nov 19, 2015 10:35 pm
by dunbarx
And here is your finish . Make a text field. Now make a table field and a button. Put something like this in fld 1:
name1
date1
name2
date2
name3
date3
name4
date4
May I assume this is how your data will come out of the files you read, as per your post?

Now in the button script:

Code: Select all

on mouseUp
   get fld 1
   set the itemDel to tab
   repeat with y = 1 to the number of lines of it step 2
      put line y of it & tab & line (y+1) of it & return after accum
   end repeat
   put accum into fld 2
end mouseUp
Craig Newman

Re: Read txt Files and populate a Table

Posted: Tue Dec 01, 2015 6:17 pm
by MaxV
You have a list of file to read like this:

Code: Select all

\\server01\TEST\Folder1\test.txt
\\server01\TEST\Folder2\test.txt
\\server01\TEST\Folder3\test.txt
Well I'd do:
########CODE#######
put URL "mylistoffiles.txt" into mylist
set itemdel to "\"
repeat for each line tFile in mylist
if there is tFile then
#we must get the file date
set the defaultfolder to (item 1 to -2 of tFile)
put the long files into temp
put line lineoffset(tFile, temp) of temp into temp
put item 5 of temp into modTime
put tFile & comma & modTime & CR after myResultList
end if
end repeat
set itemdel to comma
sort lines of myResultList numeric by item 2 of each
#####END OF CODE#####