environment vars

Things you’d like to miss in the future...
Forum rules
When reporting a bug, please include the following information: your XYplorer version (e.g., v27.90.0047), your Windows version (e.g., Win 11), and your screen scaling percentage (e.g., 125%). We recommend adding your Windows version and screen scaling percentage to your profile or signature. This will make debugging much easier for us.
Post Reply
Muroph
Posts: 561
Joined: 21 Aug 2007 16:13

environment vars

Post by Muroph »

the new environment variables handling inside paths has broken a handful of my scripts.
even something as simple as this stopped working:

Code: Select all

writefile("%temp%\test.tmp","this is a test")
My shared scripts:
TeraCopy Integration, Tag Manager, Comments Menu, Text Replacer, Image and Media Tools, Checksum Calculator, Video Calculator
only 5 URLs are allowed on the sig...

admin
Site Admin
Posts: 64898
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: environment vars

Post by admin »

Argh, yes. I forgot that a full path at the beginning is ok. :roll:

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: environment vars

Post by TheQwerty »

So now how do we use an environment variable in OpenWith and pass additional arguments?

Code: Select all

OpenWith("""%programfiles%\winrar\winrar.exe"" x -ad -- <items>", "m");
All this work to help the morons who create folders named the same as their environment variables has rendered a lot of my scripts and catalog useless in v8.50. :roll:

admin
Site Admin
Posts: 64898
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: environment vars

Post by admin »

TheQwerty wrote:So now how do we use an environment variable in OpenWith and pass additional arguments?

Code: Select all

OpenWith("""%programfiles%\winrar\winrar.exe"" x -ad -- <items>", "m");
All this work to help the morons who create folders named the same as their environment variables has rendered a lot of my scripts and catalog useless in v8.50. :roll:
Indeed, I start to regret it.

I give it one more try. But I fear ultimately the ambiguities are not solvable without a telepathic module, so it's likely that I will finally give up.

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: environment vars

Post by TheQwerty »

Clearly I have no idea how you're currently checking the paths and I'm a bit of a noob to win32 programming with no VB experience but with a bit of playing in C++ would something like this work:

Code: Select all

TCHAR path[MAX_PATH+1];
_tcscpy_s(path, _T("\"D:\\Downloads\\%username%\\test.exe\" -n"));

TCHAR pathCopy[MAX_PATH+1];
_tcscpy_s(pathCopy, path); //Copy just in case.

PathRemoveArgs(path);
TCHAR *args = _tcsninc(pathCopy, _tcslen(path)); //Store args.

PathUnquoteSpaces(path);
if (! PathFileExists(path)) {  //Try as is.
	if (! PathResolve(path, NULL, PRF_VERIFYEXISTS)) { //Try as resolved relative or unqualified.
		DoEnvironmentSubst(path, MAX_PATH);
		if (! PathFileExists(path)) {	//Try with expanded env. vars.
			if (! PathResolve(path, NULL, PRF_VERIFYEXISTS)) { //Try with expanded env. vars and resolved relative or unqualified.
				_tprintf(pathCopy); //File not found use starting value.
				return 0;
			}
		}
	}
}

PathQuoteSpaces(path);
_tcscat_s(path, MAX_PATH+1, args); //Restore the args.
_tprintf(path);
return 1;
It's not a pretty solution and probably not that efficient, but I'm sure you come up with something better. :P

admin
Site Admin
Posts: 64898
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: environment vars

Post by admin »

TheQwerty wrote:Clearly I have no idea how you're currently checking the paths and I'm a bit of a noob to win32 programming with no VB experience but with a bit of playing in C++ would something like this work:

Code: Select all

TCHAR path[MAX_PATH+1];
_tcscpy_s(path, _T("\"D:\\Downloads\\%username%\\test.exe\" -n"));

TCHAR pathCopy[MAX_PATH+1];
_tcscpy_s(pathCopy, path); //Copy just in case.

PathRemoveArgs(path);
TCHAR *args = _tcsninc(pathCopy, _tcslen(path)); //Store args.

PathUnquoteSpaces(path);
if (! PathFileExists(path)) {  //Try as is.
	if (! PathResolve(path, NULL, PRF_VERIFYEXISTS)) { //Try as resolved relative or unqualified.
		DoEnvironmentSubst(path, MAX_PATH);
		if (! PathFileExists(path)) {	//Try with expanded env. vars.
			if (! PathResolve(path, NULL, PRF_VERIFYEXISTS)) { //Try with expanded env. vars and resolved relative or unqualified.
				_tprintf(pathCopy); //File not found use starting value.
				return 0;
			}
		}
	}
}

PathQuoteSpaces(path);
_tcscat_s(path, MAX_PATH+1, args); //Restore the args.
_tprintf(path);
return 1;
It's not a pretty solution and probably not that efficient, but I'm sure you come up with something better. :P
Extracting the path and checking for existence is a possibility but it would indeed slow down the whole thing too much. I will rather try to solve it on a purely syntactical level.

admin
Site Admin
Posts: 64898
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: environment vars

Post by admin »

admin wrote:Extracting the path and checking for existence is a possibility but it would indeed slow down the whole thing too much. I will rather try to solve it on a purely syntactical level.
PS: The checking for existence method would also fail when new files are to be created: they do not exist, yet there path is perfectly alright.

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: environment vars

Post by TheQwerty »

admin wrote:
admin wrote:Extracting the path and checking for existence is a possibility but it would indeed slow down the whole thing too much. I will rather try to solve it on a purely syntactical level.
PS: The checking for existence method would also fail when new files are to be created: they do not exist, yet there path is perfectly alright.
Indeed, but I wasn't aiming to provide a way to further this idiocy of creating items with "%...%" names, I just want my catalog and scripts to work correctly! :P

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: environment vars

Post by TheQwerty »

Not sure if there's any remaining/new problems now, but my catalog/scripts work again! :D

Post Reply