Read txt Files and populate a Table

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
ChrisM
Posts: 24
Joined: Sat Mar 29, 2014 3:11 pm

Read txt Files and populate a Table

Post by ChrisM » Thu Nov 19, 2015 9:35 pm

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

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Read txt Files and populate a Table

Post by Simon » Thu Nov 19, 2015 9:41 pm

Hi Chris,
Here is your start;
http://lessons.livecode.com/m/4603/l/44 ... ng-to-file

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7154
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Read txt Files and populate a Table

Post by dunbarx » Thu Nov 19, 2015 10:35 pm

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

MaxV
Posts: 1577
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Read txt Files and populate a Table

Post by MaxV » Tue Dec 01, 2015 6:17 pm

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#####
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”