Jump to content
Macro Express Forums

Parsing A Directory Location


Recommended Posts

It's real easy. Use the “Variable Set From File” command. In there check out the “Get File Path Info” section. In your example I would get Drive and path as T1 and T2 and then set variable T3 to “%T1%%T2%”. Sleazy!

Link to comment
Share on other sites

For anybody that is interested, here is the longhand way of accomplishing the same thing that Cory was able to do with a single statement. I did not know about Cory's Variable Set From File command with Get File Path Info until his post, so I did it the long way. In general, Variable Set From File command is better than my example, although some people may find my technique instructive and useful in other situations where you need to parse out information.


This macro breaks up a full path and file name, and puts each component in a separate variable. Comments in the macro define which component goes in which varaible.


Run it first "as is" to get an idea of how it works; the results show up in a text box.


Although this example directly assigns the path name and File to variable T1, it works just as well no matter how the path and file name string gets into variable T1 For example, you can use set text string variables - said value to filename (prompt).


For those not familiar with how to copy macro code from the bulletin board: Copy the code below. In macro express, go to Macros: Add macro: select 'no activation' and press 'direct editor' button. Taste in the code below and save. At this point, if you wish, you can close the direct editor and reopen the macro in the scripting editor.


<REM2:select file and parse out folder><REM2:T1 = file name with path><TVAR2:01:01:C:\Documents and Settings\Owner\Desktop\abcd.pdf><IVAR2:01:12:1><REP3:01:%N1%:0000-1:%N1%:1:02:><TMVAR2:10:02:01:N02:001:><IFVAR2:1:02:1:\><BREAK><ENDIF><ENDREP><REM2:T3 = path including final \><TMVAR2:10:03:01:001:N02:><REM2:T5 = path without final \><NMVAR:02:03:1:0000002:2:0000001><TMVAR2:10:05:01:001:N03:><REM2:T4 = file name without path><TMVAR2:09:04:01:000:000:><TMVAR2:11:04:00:001:N02:><REM2:T6 = file name without extension><REM2:loop from end of string with a negative increment><REM2:             faster and required since some files have two periods><IVAR2:01:12:4><REP3:01:%N1%:0000-1:%N1%:1:02:><TMVAR2:10:02:04:N02:001:><IFVAR2:1:02:1:.><BREAK><ENDIF><ENDREP><NMVAR:02:03:1:0000002:2:0000001><TMVAR2:10:06:04:001:N03:><REM2:T7 = extension><NMVAR:01:03:1:0000002:2:0000001><NMVAR:02:04:1:0000001:1:0000002><TMVAR2:10:07:04:N03:N04:><REM2:show resuts><TBOX4:T:1:CenterCenter000500000400:000:ResultsFile name with path = %T1%

File name = %T4%

File name without extension = %T6%

Path with ending \ = %T3%

Path with no ending \ = %T5%

Extension = %T7%
><REM2: ><REM2: ><REM2: ><REM2: >

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...