Non-explicit filepaths

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
Warren
Pro Scripter
Posts: 83
Joined: Sun Oct 08, 2017 11:57 pm

Non-explicit filepaths

Post by Warren » Fri Nov 03, 2017 8:23 pm

Just trying to include a script in a shared dropbox folder. The filepath includes the username, and that is different per machine, so it might be:

Include>C:\Users\Administrator\Dropbox\myScript.scp

but if the username is different than "Administrator", the filepath doesn't work.

Windows filepath info I found online says to use double dot delimiter, but the following does not work.

Include>C:\Users\..\Dropbox\myScript.scp

It's not a subdirectory of the executing script's directory, so I'm not seeing some other way of using relative filepaths. Does MS use some other method of non-explicit filepaths that allows me to do the equivalent of /../

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

Re: Non-explicit filepaths

Post by Marcus Tettmar » Fri Nov 03, 2017 8:43 pm

Use the DESKTOP_DIR variable:

MessageModal>DESKTOP_DIR
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

Warren
Pro Scripter
Posts: 83
Joined: Sun Oct 08, 2017 11:57 pm

Re: Non-explicit filepaths

Post by Warren » Fri Nov 03, 2017 8:53 pm

Sorry, I realized my generic example referred to the desktop, and that something specific to desktop like DESKTOP_DIR might exist, so I edited question to be specific to what I'm actually looking at which doesn't reference desktop. I had assumed at first that since my Dropbox folder is on the desktop that the filepath of files within would reflect that, but they don't. I guess that's a shortcut, because actual filepath is:

Include>C:\Users\Administrator\Dropbox\myScript.scp

A couple other ways to avoid explicit username that I found online, but that did not work:

Include>~\Dropbox\myScript.scp

Include>C:\Users\%USERPROFILE%\Dropbox\myScript.scp

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

Re: Non-explicit filepaths

Post by Marcus Tettmar » Fri Nov 03, 2017 9:27 pm

Try:

Code: Select all

GetEnvVar>USERPROFILE,profilePath
Let>dropboxPath=%profilePath%\Dropbox
However, I don't know if you can assume that Dropbox is always in the profile. Maybe. Maybe not. At some point you might just have to store system specific settings in the registry or an INI file.

Consider using an INI file which you store in the same folder as the script and then refer to it with:

Code: Select all

ReadIniFile>%SCRIPT_DIR%\mysettings.ini,SETTINGS,DropBoxDir,dropboxPath
Your INI file would look like:

Code: Select all

[SETTINGS]
DropBoxDir=c:\bla\bla\dropbox
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

Warren
Pro Scripter
Posts: 83
Joined: Sun Oct 08, 2017 11:57 pm

Re: Non-explicit filepaths

Post by Warren » Sat Nov 04, 2017 12:17 am

Setup is always the same, but most are Windows 2012, and a few are other Windows builds from other providers where the default may be "Admin" rather than "Administrator" or some such variation.

Looks like GetEnvVar>USERPROFILE,profilePath was exactly what I needed.

Thx.

Post Reply