Getting Temp Directory Path

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

Getting Temp Directory Path

Post by kpassaur » Tue Feb 03, 2009 12:03 pm

This should be easy, but I cannot seem to figure it out.

What I need to do is return the path of a temp directory.

The is the actual directory

C:\Documents and Settings\Keith Passaur\Local Settings\Temp\TransActPOS\DocScanMan\combinepdf

When I am writing my script I am using the %TEMP_DIR% command to write a line as seen below:

C:\DOCUME~1\KEITHP~1\LOCALS~1\Temp\TransActPOS\DocScanMan\Combinepdf\PO2.pdf~02-03-2009 : 06:42:44

The difficulty is the application that processes this line parses it with a "~" therefore since the "~" is in the line I write it will not work properly.

What I am looking for is a way to convert it to the full path without the "~".

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

Post by Marcus Tettmar » Tue Feb 03, 2009 1:02 pm

TEMP_DIR is obtained by calling Windows' GetTempPath function. Documented here:

http://msdn.microsoft.com/en-us/library ... S.85).aspx

Note:
The GetTempPath function checks for the existence of environment variables in the following order and uses the first path found:

The path specified by the TMP environment variable.
The path specified by the TEMP environment variable.
The path specified by the USERPROFILE environment variable.
The Windows directory.
If you are getting "~" characters in the path then that must be how it is set up on your system in your environment variables (one or other of the above). The function can only report what the system has it set to.

Open up a command console (cmd.exe) and type:

SET TMP
or
SET TEMP
or
SET USERPROFILE

And you will see exactly what values these variables are set to.

Mine contain the full, unabbreviated paths.

Change them if necessary.

[/quote]
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

return full path

Post by kpassaur » Tue Feb 03, 2009 2:14 pm

Mine does not return the full path, that is the issue. I have changed the script to

C:\Documents and Settings\%USER_NAME%\Local Settings\Temp\TransActPOS\DocScanMan\combinepdf

which will work for XP. However, it will not for Vista. So I need a way to change it to report back without the "~". There must be a setting somewhere that controls it if yours is displaying the full path.

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

Post by Marcus Tettmar » Tue Feb 03, 2009 2:54 pm

There must be a setting somewhere that controls it if yours is displaying the full path.
I don't think so. It is just the way the path is stored in the environment variable. Go to DOS and type SET and you'll see.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

Path

Post by kpassaur » Tue Feb 03, 2009 4:05 pm

I have gone into dos and I have run it. Unfortunatly it displays the short path not the long path.

My thought is that if yours is displaying the long or full path there must be a setting that can be changed so that it returns the long path on my machine.

It is either that or find a way to convert a short path into a long path.

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

Post by Marcus Tettmar » Tue Feb 03, 2009 4:31 pm

Ok, had a hunt around and came across this genious trick using a shortcut that never gets created [it sets the shortcuts target to the shortname and then retrieves the target again, it being returned in the long format]:

Code: Select all

VBSTART
Function GetLongName(shortName)
  dim oArgs, oShell, oSC        
  Set oShell = CreateObject("WScript.Shell")      
  ' Link will not be created!    
  Set oSC = oShell.CreateShortcut("c:\foo.lnk")      
  
  oSC.TargetPath = shortName   
  GetLongName = oSC.TargetPath 
  Set oSC = Nothing 
End Function
VBEND

VBEval>GetLongName("c:\progra~1"),output
MessageModal>output
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

Path

Post by kpassaur » Tue Feb 03, 2009 4:39 pm

Thanks Marcus

I just found a similar one, however, I couldn't get it to work. Yours is great.

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Wed Feb 04, 2009 6:29 am

Hi Marcus,

I also wanted to say thanks for the bit of code above. I had similar problem a while back and resorted to hard-coding the path I needed. Now with this, I can convert from shortname to longname as required... very nice.

In testing your posted code, I also discovered that:

- if you have Word Wrap turned on in the editor
- and you run a macro from within the editor
- while the macro is running, it turns off Word Wrap in the editor so if you have some long lines, you may see them jostle around a bit
- once the macro terminates, Word Wrap seems to turn itself back on and the text appears as it did before you ran the macro

To see this:

- Turn Word Wrap on in the editor
- CTRL-A copy this entire forum post and paste it into a new macro
- Edit/Remove Trailing Spaces
- Block Comment out all the lines preceding your example code
- Block Comment out all the lines following your example code
- Maximize the editor window
- tap CTRL-Home to position the cursor at the beginning of the first line
- Run the macro from within the editor (F9 or click toolbar icon)
- Notice the dialog pop up with the results and suddenly the editor is displaying a horizontal scroll bar which makes me think Word Wrap must have been switched off... lines near the bottom jostle around... no more multi-line lines are being displayed in the editor
- As soon as you click OK on the dialog and the macro terminates, the horizontal scrollbar goes away and the lines at the bottom of the screen jostle back to how they looked before we ran the macro.

Marcus, is this intentional behavior, something that can't be helped... or can this be fixed so that running that a macro from within the editor does not cause this effect?
Last edited by jpuziano on Fri Feb 20, 2009 5:20 am, edited 1 time in total.
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

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

Post by Marcus Tettmar » Wed Feb 04, 2009 6:38 am

Intentional. Designed. Needed by debugger. Am sure we've had this discussion before - remember when wordwrap was requested this caveat was explained.
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
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Wed Feb 04, 2009 7:23 am

OK, thanks for the fast response and take care.
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Fri Feb 13, 2009 9:36 pm

Marcus wrote:Macro Scheduler 11.1.04 Update is now available with the following fixes:

Change: Debugger no longer temporarily disables wordwrap - no longer required
- plus other fixes, see http://www.mjtnet.com/mswhatsnew.htm for the rest...

Thanks Marcus... even small changes like this are appreciated.

Keep up the great work and take care.
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

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