 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
kishjeff
Joined: 17 Aug 2004 Posts: 2 Location: Grand Rapids Michigan
|
Posted: Tue Aug 17, 2004 3:44 am Post subject: file parsing and creation |
|
|
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 |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Tue Aug 17, 2004 4:16 am Post subject: |
|
|
| 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 |
|
 |
Guest
|
Posted: Tue Aug 17, 2004 1:22 pm Post subject: |
|
|
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
|
Posted: Tue Aug 17, 2004 1:52 pm Post subject: |
|
|
| 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 |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|