AutoHotkey Community

It is currently May 26th, 2012, 12:38 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: December 16th, 2008, 10:53 pm 
Offline

Joined: December 9th, 2007, 4:24 pm
Posts: 20
I am attempting to use a simple batch file to process an entire directory of over 4000 files with a command line version of a program. Something tells me that I am missing something simple so I wanted to ask for outside help.

I am using gpsbabel.exe to reduce the number of duplicate points in GPS log files. Depending on the amount of time spent stationary while logging a trip, reducing the number of duplicates can substantially reduce both the file size and the load times of the log files.

To do this I wrote a simple batch file with the correct parameters to perform said operation. The batch file works, no problem. But the idea of dragging each separate log file onto this batch file 4000 times is depressing.

The program execution time is variable based on the file size and number of stored points in the log file. For a short log file it can execute in just 10 seconds or so, but for a logged trip of several hours with 20000 stored points, it can take upwards of 5 minutes and longer. Point being, a simple delay timer will not suffice in my situation. I can have multiple instances of the exe file running, but not 4000 instances! And, unfortunately, that is exactly what I keep running into.

So, what I am looking for is how to make AHK search a particular folder for files with a modification date before a certain date, select one of those files and process it using the batch file I created with the correct parameters, wait for the first one to finish processing, then rescan the folder and take the next one it finds and perform the same action. Kind of like Robotask but forcing it to wait to perform the next task until the first one completes.

Any ideas?

Thanks,
Jim


Last edited by ai4fu on December 17th, 2008, 5:36 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 16th, 2008, 11:30 pm 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
99.9% of what you just said went WAY over my head. HOWEVER, lucky for you, I think the 0.1% that I did understand will help you.

From what it sounds like, you need to loop through files in a folder, and do "some task" to them. If this is the case, then a file loop is what you need.

Inside this loop, use RunWait to run your batch program, and AHK will wait (however long) until it finishes.

You can do whatever you need in the loop, then after that iteration is done, it finds the next file, and repeats.

Hopefully that is what you need. If not, or if you have any more questions, don't hesitate to ask.

_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2008, 12:02 am 
Offline

Joined: December 9th, 2007, 4:24 pm
Posts: 20
animeaime wrote:
99.9% of what you just said went WAY over my head. HOWEVER, lucky for you, I think the 0.1% that I did understand will help you.


Edit: Thanks for your input! Always helps to have fresh eyes ona problem. /edit

Actually, I'm pretty sure you are dead on track, I had come to the same conclusion and am working on implementing it now. Being the slow ponderous coder that I am, I should be done in a week. :lol:

And no, you are not in over your head, I am. The extraneous info was because I have been chewed on here (kinda) for not providing enough info, so this time I went with too much. Nothing like overkill.

Will post back if I ever get it solved.

Thanks,
Jim


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2008, 4:55 am 
Offline

Joined: December 9th, 2007, 4:24 pm
Posts: 20
OK, I think I need more help if someone has the time:

Code:
OldestTime = 200812080001 ;Setting oldest time to Dec 8, 2008 12:01AM

Loop, \*.gpl ;Hopefully looping all files in the scripts working directory
{
      if (A_LoopFileTimeModified < OldestTime) ;Getting each file, one at a time, that is older than OldestTime
   {
      RunWait gpltrimmer.bat, A_LoopFileName ;Running a single instance of gpltrimmer.bat and passing the currently selected file from the loop as a parameter and waiting until the batch file terminates before continuing.
   }
}


The idea is to cause the script to select each file older than the specified date in turn, and pass it on to gpltrimmer.bat, wait for gpltrimmer.bat to complete, then proceed to the next file. I accomplish this manually by dragging the intended file (selected by manually checking the date) and dropping it onto the gpltrimmer.bat shortcut.

Doing it manually produces the desired results but I shudder at doing it 4000 times.

Any one care to take a swing? I am lost (doesn't take much... :roll: )


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2008, 5:03 am 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
did you pass the file name as an argmunt? this has the same effect as dropping it - it will be argument 1.

_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2008, 5:06 am 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
also, don't use < when comparing times, see the note on this page. Instead use envsub. read the note, it will make it clear.

_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2008, 5:12 am 
Offline

Joined: December 9th, 2007, 4:24 pm
Posts: 20
Well, I thought I was doing that in this line:
ai4fu wrote:
Code:
RunWait gpltrimmer.bat, A_LoopFileName ;Running a single instance of gpltrimmer.bat and passing the currently selected file from the loop as a parameter and waiting until the batch file terminates before continuing.



But maybe I missed? Maybe I don't understand how an argument is placed in the code, I tried the doc and help but maybe I read it wrong.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2008, 5:18 am 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
No, check RunWait

Code:
Run, Target [, WorkingDir, Max|Min|Hide|UseErrorLevel, OutputVarPID]


The description for Target wrote:
To pass parameters, add them immediately after the program or document name. If a parameter contains spaces, it is safest to enclose it in double quotes (even though it may work without them in some cases).


Also, I would use

Code:
A_LoopFileFullPath . "" . A_LoopFileName


for the File's pathname.

This way if you have subfolders the path points to the file in the subfolder (rather than in the working directory). Just a precaution in case you want to include subfolders later - and it causes no problems or delay if you don't opt to iterate over subfolders.

_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2008, 5:22 pm 
Offline

Joined: December 9th, 2007, 4:24 pm
Posts: 20
I wound up having to solve this by creating a CMD file (gpltrimmer.cmd). Maybe one of the gurus on here that are familiar with both can tell me how I could have acheived the same effect with AHK.

Code:
lfnfor on
FOR %%X IN (*.gpl) DO gpsbabel.exe -t -i gpl -f "%%X" -x position,distance=25f -o gpl -F "%%X"


All pertinent files (gpltrimmer, gpsbabel) were copied into the directory where the target files were located so as to simplify the process for myself. I can always work out the absolute or relative target paths later.

Thanks to animeaime for his help.

Please feel free to translate this over to AHK, anyone at all, as I would rather keep learning AHK than resorting to "old school" stuff.

By the way, the script is running as I write this, just like I wanted, one file at a time, one window, using about 50-55% processor (gpsbabel is CPU intensive). Beats the heck out of having to hit CTRL^C and close hundreds of DOS windows!

Thanks again,
Jim


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2008, 6:18 pm 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
1) NAOPAG - NAO Pag!!! OK made it up, but still "Not All On-line Persons are guys..."

2) I'm not too familiar with batch file commands, but I think this is what you are doing.

It looks like you are looping through all .gpl files and doing something.

This will loop through all .gpl files in the working directory (and subfolders)

Code:
Loop, *.gpl, 0, 1
{
    ;Do Something
}


Now for the "Do Something".

It looks like you are running "gpsbabel.exe" with parameter "-t -i gpl -f <File> -x position,distance=25f -o gpl -F <File>" where <File> is the current file.

This would be

Code:
;Declared Outside of loop
GPSBabel := "gpsbabel.exe"

;Declared In loop
CurrentFile = %A_LoopFileFullPath%\%A_LoopFileName%
arguments = -t -i gpl -f %CurrentFile% -x position,distance=25f -o gpl -F %CurrentFile%

RunWait, %GPSBabel% %arguments%


Then, combine them (and add the option to selecet working path) and you get

Code:
;Specify "" for ThisDirectory to use A_WorkingDir as the working directory
;must contain trailing backslash if directory(i.e C:\) to work as expected
ThisDirectory := ""

;Path for GPSBabel
GPSBabel := "gpsbabel.exe"

Loop, %ThisDirectory%*.gpl, 0, 1
{
    CurrentFile = %A_LoopFileFullPath%
    arguments = -t -i gpl -f %CurrentFile% -x position,distance=25f -o gpl -F %CurrentFile%

    MsgBox, % CurrentFile . "`nRun: " . GPSBabel . "`nWith arguments: " . arguments
   
    ;A_WorkingDir is used as the working directory
    ;RunWait, %GPSBabel% %arguments%
   
    ;remove after you verify that the current file / args are right
    break
}


Like all DOS stuff, if you use "\" for the directory it will use the current directory (whatever drive you run the code from). So, "\SomeFolder" would loop through "SomeFolder" on the current drive (in case you need portable use, via flash drive, external drive, CD/DVD, etc.)

Like always, if you have any questions, don't hesitate to ask.

_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2008, 6:33 pm 
Offline

Joined: December 9th, 2007, 4:24 pm
Posts: 20
animeaime wrote:
1) NAOPAG - NAO Pag!!! OK made it up, but still "Not All On-line Persons are guys..."


I must admit, I only copy/pasted your user name, I didn't really read it. If I had, I might have picked that up. My humble apologies first of all. :oops:

Second, thanks so much for your help. It is so much easier to glean what I need from examples like the ones you wrote, than the ones in the help file. The help file is recursive in that it refers back to other parts of itself to define things that are used in defining things that are...... :shock: (this is how I look after trying to read up on something in the help file for AHK)
If they need help writing AHK for Dummies(people like me), I know where to tell them to ask. I really appreciate your help. I never leave this forum without learning something. In this case it was how to pass on parameters to an external program. THat was what was holding me back.

Please forgive the social faux pax.

Thanks,
Jim


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2008, 6:41 pm 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
np, I'm sure I've done the same - it's the problem of English lacking a third person, gender-neutral pronoun. I usually would say "thank you ai4fu for your help. Or would use the "singular they", "I would like to thank ai4fu for their help."

But, no prob - forgive and forget.

p.s. lol, yeah the help files can be something.

_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, Morpheus, patgenn123, SKAN and 12 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group