Inner Outer Loops

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
edauthier
Pro Scripter
Posts: 84
Joined: Sun Apr 13, 2003 1:26 pm
Location: USA

Inner Outer Loops

Post by edauthier » Wed Jul 23, 2008 2:06 am

I have been struggling with code for the following and would appreciate any advice.

Read thru a specific file folder and read the first line of each file within the folder. All are text files.

While doing this I would like to parse the 1st line and write specific fields from the line to another single text file. The First line is delimited by pipe.

OuterLoop>ReadFile
InnerLoop>ReadLine, write results

Thanks, Ed

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Jul 23, 2008 7:26 am

If I've followed you correctly there's actually only one loop here. Something like:

Code: Select all

//get list of files in folder
GetFileList>c:\folder\*.*,file_list
Separate>file_list,;,files

//loop through list of files
Let>k=0
Repeat>k
  Let>k=k+1
  Let>this_file=files_%k%

  //read first line of file
  ReadLn>this_file,1,line

  //split line into fields using pipe as delimiter
  Separate>line,|,fields

  //write fields 1,3, and 5 to another file
  WriteLn>outputfile,res,fields_1
  WriteLn>outputfile,res,fields_2
  WriteLn>outputfile,res,fields_3

  //or, say you want them on the same line:
  WriteLn>outputfile,res,%fields_1% %fields_2%, %fields_3%

Until>k=files_count
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

edauthier
Pro Scripter
Posts: 84
Joined: Sun Apr 13, 2003 1:26 pm
Location: USA

Post by edauthier » Wed Jul 23, 2008 12:41 pm

Thanks Marcus,
This will be perfect for me.

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts