locate directory and find file

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
Snickers
Macro Veteran
Posts: 151
Joined: Thu Dec 09, 2004 3:01 pm
Location: Somewhere in TX

locate directory and find file

Post by Snickers » Thu Sep 13, 2007 12:08 pm

Lets say I compile a macro named SampleCM.exe and I place this SampleCM.exe is a any folder I want on my hard drive.

Then I place a text file with an unknown name into that folder.


What command should I include in the SampleCM.exe that would allow SampleCM.exe to search the folder that SampleCM.exe was placed into for the random textfile.


Here's my purpose.
The user will place the SampleCM.exe into any folder they wish. The variables that are used in SampleCM.exe are gathered from a textfile that is placed into the same folder that SampleCM.exe is placed.


I know I can use the following code to determine what the name of the .txt file is:
[code]
GetFileList>C:\folder\*.txt,files
Separate>files,C:\folder\,name
MDL>%name_2%
[/code]

But what command can I use to locate the folder that the user has put the actual macro and text file into?

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Sep 13, 2007 12:24 pm

The COMMAND_LINE variable tells you what drive:\path\file was executed. So one way to do this would be:

Code: Select all

Separate>%COMMAND_LINE%,\,path
sub>path_count,1
Let>k=1
Repeat>k
  add>k,1
  Let>var=path_%k%
  Concat>path_1,\%var%
Until>k,path_count
\\Then to have the name surrounded by quotes
Concat>path_1,"
\\Or to have no quotes
StringReplace>path_1,",,path_1

Snickers
Macro Veteran
Posts: 151
Joined: Thu Dec 09, 2004 3:01 pm
Location: Somewhere in TX

Post by Snickers » Thu Sep 13, 2007 12:39 pm

Man, I hate to make you work more. I even looked at that in the help file but didn't think it was what I needed. I need to get a better understanding of the uses of the system variables.

[code]
COMMAND_LINE
Full command line string (path of running executable and parameters passed on the command line)
[/code]

Thank you, again!

In case anyone is interested; here is the full function:

[code]
//find exe to declare variables
Separate>%COMMAND_LINE%,\,path
sub>path_count,1
Let>k=1
Repeat>k
add>k,1
Let>var=path_%k%
Concat>path_1,\%var%
Until>k,path_count
//Take quotes away
StringReplace>path_1,",,path_1
//link path to .txt file
GetFileList>%path_1%\*.txt,files
Separate>files,%path_1%\,name
let>location=%path_1%\%name_2%
//display a message modal with the full path and .txt file name
MDL>%location%
[/code]

If there is more than one text file, a (;)semi-colon will appear at the end of the path. You may need to change the code above to seperate the semi-colon from the path\*.txt; if you expect there to be more than one text file.
Last edited by Snickers on Thu Sep 13, 2007 2:28 pm, edited 1 time in total.

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

Post by Marcus Tettmar » Thu Sep 13, 2007 12:57 pm

While COMMAND_LINE can be used, the variable you are after is SCRIPT_DIR

From help:
"SCRIPT_DIR Directory of running script"

SCRIPT_DIR is "Location of Me". Whether "Me" is a compiled EXE or a .SCP file SCRIPT_DIR will return the folder that "Me" is in.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Sep 13, 2007 1:35 pm

Hmmm... SCRIPT_DIR added back in aught three. The same time that the COMMAND_LINE variable was added. I have multiple scripts dissecting COMMAND_LINE where SCRIPT_DIR would have been much easier.

Thank you Marcus, your software is amazing.

Snickers
Macro Veteran
Posts: 151
Joined: Thu Dec 09, 2004 3:01 pm
Location: Somewhere in TX

Post by Snickers » Thu Sep 13, 2007 2:25 pm

Oh, wow! That is insanely more simplistic.
From this:
[code]
//find exe to declare variables
Separate>%COMMAND_LINE%,\,path
sub>path_count,1
Let>k=1
Repeat>k
add>k,1
Let>var=path_%k%
Concat>path_1,\%var%
Until>k,path_count
//Take quotes away
StringReplace>path_1,",,path_1
//link path to .txt file
GetFileList>%path_1%\*.txt,files
Separate>files,%path_1%\,name
let>location=%path_1%\%name_2%
//display a message modal with the full path and .txt file name
MDL>%location%
[/code]

To this:

[code]
GetFileList>%SCRIPT_DIR%\*.txt,files
Separate>files,%SCRIPT_DIR%\,name
let>location=%SCRIPT_DIR%\%name_2%
[/code]

I love it!

If there is more than one text file, a (;)semi-colon will appear at the end of the path. You may need to change the code above to seperate the semi-colon from the path\*.txt; if you expect there to be more than one text file.

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Thu Sep 13, 2007 3:00 pm

Yep, if you distribute your scripts SCRIPT_DIR is a lifesaver :D

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