AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

file parsing and creation

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
kishjeff



Joined: 17 Aug 2004
Posts: 2
Location: Grand Rapids Michigan

PostPosted: Tue Aug 17, 2004 3:44 am    Post subject: file parsing and creation Reply with quote

Greetings.
I'm totally new here. I've perused the boards, and read a fair amount of documentation.. Can someone recommend a sample script or a set of likely functions to use for the following task?

I need to be able to select one or more files of my choice and:
- parse each one, picking out elements that are desired (maybe create table statements or some others, and
- create a new output file (this is the thing I could not find.. I saw appendfile, but not the creation of one), and
- as I find each element I desire (say something after "create table' between the following parenthesis and it's mate) and modify it and write it to the output file and
- when I'm done, save the output file, or message that there was a problem.
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Tue Aug 17, 2004 4:16 am    Post subject: Reply with quote

Quote:
select one or more files of my choice

There's an example of how to do a multiple-select file selection at the bottom of this page: http://www.autohotkey.com/docs/commands/FileSelectFile.htm

Quote:
I saw appendfile, but not the creation of one

To overwrite a file, use FileDelete prior to calling FileAppend as shown in the example below.

Quote:
parse each one, picking out elements that are desired...create a new output file

To parse the lines in a file, one by one, and output new info to an output file, the general format is:
Code:
FileDelete, OutputFilename.txt
Loop, read, InputFilename.txt, OutputFilename.txt
{
     Loop, parse, A_LoopReadLine, `,
     {
          FileAppend, %A_LoopField%`,
     }
     FileAppend, `n
}

The above example assumes the fields of each line are delimited by comma. It also creates OutputFilename.txt the same as its input filename, so you should alter it to do any processing of the data before actually writing it with FileAppend.

Here are more details for parsing and file-reading loops.
Back to top
View user's profile Send private message Send e-mail
Guest






PostPosted: Tue Aug 17, 2004 1:22 pm    Post subject: Reply with quote

Oh Geez,

I found some of this stuff later in the evening (last night). Thanks for the pointers.

Is there a way of figuring out what delimeter was encountered (so I can parse along, and know when I'm in a parameter list (found a left parens), and when I'm done (found a right parens) etc?


Thanks for your help. This is a pretty interesting piece of software.

Jeff
Back to top
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Tue Aug 17, 2004 1:52 pm    Post subject: Reply with quote

Quote:
Is there a way of figuring out what delimeter was encountered

Not directly, but it's a good suggestion so I think it will be added. As a workaround, you can parse the line character by character (i.e. omit the delimiter parameter) and thus check which delimiter occurs.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group