WAD Nested variable expansion in PDIR's @function[*]?

May 20, 2008
11,409
99
Syracuse, NY, USA
SETDOS /X-4 makes this possible(note that the filename contains '%'):
Code:
c:\users\vefatica\appdata\local\microsoft\windows\temporary internet files\content.ie5\w2k0d1cw>
setdos /x-4 & do f in *Lasda* (echo %f^n%@inode[%f]) & setdos /x+4
%7bde374417-0d84-422b-b6c5-268c52b40889%7d_23145-Lasda-5806[1].jpg
00B70000:000121AC
How can I get that info with PDIR /(@inode[*])? SETDOS /X-4 fails to stop the nested expansion.
Code:
c:\users\vefatica\appdata\local\microsoft\windows\temporary internet files\content.ie5\w2k0d1cw>
setdos /x-4 & pdir /(f @inode[*]) *Lasda* & setdos /x+4

TCC: (Sys) The system cannot find the file specified.
 "%@inode["C:\Users\vefatica\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.IE5\W2K0D1CW\-0d84-422b-b6c5-268c52b40889-Lasda-5806[1].jpg"]"
 

rconn

Administrator
Staff member
May 14, 2008
12,350
150
WAD -- PDIR isn't doing nested variable expansion. PDIR substitutes the filename for the *, and expands the variable "%@inode[filename]". When the variable expansion routine processes the variable function, it looks for variables in the arguments and substitutes those as well. This is *not* nested variable expansion -- that would be if the variable contained another variable.
 
May 20, 2008
11,409
99
Syracuse, NY, USA
WAD -- PDIR isn't doing nested variable expansion. PDIR substitutes the filename for the *, and expands the variable "%@inode[filename]". When the variable expansion routine processes the variable function, it looks for variables in the arguments and substitutes those as well. This is *not* nested variable expansion -- that would be if the variable contained another variable.
1. In http://jpsoft.com/forums/threads/pdir-files-with-percent-sign-in-name-cause-not-listing-other-files-in-directory.4016/ (which deals precisely with '%' in file names in @FUNCTION[*] in PDIR (but with a different gripe)), you said:
If you don't want your filenames expanded, then either don't create such highly dubious (and impractical) filenames, or turn off nested variable expansion before calling PDIR.
That's what made me think it wasn't working correctly. What did you mean by that?
2. How do I get around the problem? There are more such files on my system drive. I didn't name them; Microsoft did.
 
May 20, 2008
3,515
4
Elkridge, MD, USA
Vince:
I have not been able to figure out what you had tried to do above, because of the length of line. You could just map - temporarily - to a single letter, whether by SUBST or NET USE or otherwise, so you would not have to break lines. Likewise, a single long line of code requires horizontal scrolling, not visible at once, while a batch file makes it easier to read. Only the logistics of posting, not the substance, and there may be cases when the "one-liner" is the substance.

I've been using PDIR for years without problems, including the @inode[*] function, never bothering in years with the "expansion" feature (setdos /x). I cannot translate the tongue in cheek to a real example. Most of the time I just use the format with the implied percent sign (%); only on rare occasion do I need to double the percent sign, usually for nested functions.

Can you give a real example of a file name that includes a percent sign?
 
May 20, 2008
11,409
99
Syracuse, NY, USA
Here it is with a SUBST. In the first example, the file name is correct. In the second example, "%7bde374417" and "%7d_23145" were expanded to empty strings.
Code:
o:\> setdos /x-4 & do f in *Lasda* ( echo %f^n%@inode[%f] ) & setdos /x+4
%7bde374417-0d84-422b-b6c5-268c52b40889%7d_23145-Lasda-5806[1].jpg
00B70000:000121AC

o:\> setdos /x-4 & pdir /(fn"^n"@inode[*]) *Lasda* & setdos /x+4
TCC: (Sys) The system cannot find the file specified.
"%@inode["O:\-0d84-422b-b6c5-268c52b40889-Lasda-5806[1].jpg"]"
 
May 20, 2008
3,515
4
Elkridge, MD, USA
You are not surprised that IE is not compatible with command line utilities, be it CMD or TCC, do you?

I suggested that while universal method dies not exist, you could write a plug-in to handle this specific style of abomination. and do some of the processing as strings, and report both the file name (unparsed) as well as its inode.
 
May 20, 2008
11,409
99
Syracuse, NY, USA
You are not surprised that IE is not compatible with command line utilities, be it CMD or TCC, do you?

I suggested that while universal method dies not exist, you could write a plug-in to handle this specific style of abomination. and do some of the processing as strings, and report both the file name (unparsed) as well as its inode.
Well I can't rewrite PDIR. And there's nothing special about @INODE. There's something unfortunate about how PDIR handles @FUNCTION[*]. It replaces '*' with the filename and sends the result off to the parser. Being on the inside, that filename is going to get evaluated first, and variables will be expanded (unless you've turned off all variable expansion, which would kill the expanding of @FUNCTION). You can't even doctor the string (say with @replace[%%,%%%%,*]) because '*' is expanded before @replace.
I suppose TCC could internally doctor the filename (doubling the %s) but I'm not sure that'd work well and I suppose it'd take significant time. I also suppose TCC could, internally, use a variable with the actual file name in it ... replace '*' with %_PDIR_FILE_NAME ... so that SETDOS /X-4 would keep the actual file name from being parsed.
 
Similar threads
Thread starter Title Forum Replies Date
B Problem with color in nested shells Support 1
R Problem with %_do_loop in nested do loops Support 2
C Nested IF syntax — TCC behaving differently to CMD Support 12
C FOR loop with nested IF / IFF Support 9
jbanaszczyk Broken For and nested Do Support 2
vefatica _DO_LOOP and nested DOs? Support 8
vefatica Single-line DO inside nested multi-line DOs? Support 9
R How to? debug a nested batch file Support 2
G WAD Nested if exits enclosing if Support 3
M A problem with nested Gosub's/ExecStr's Support 14
C CMD's "nested quote" syntax Support 3
dcantor Terminology question: nested vs. recursive Support 0
R nested for loop question Support 3
J Nested for loops and quotes Support 12
D can PDIR list full filepaths of docs in a nested folder? Support 13
D Parsing an array variable to an array does not work Support 5
sully9 How to? Unexpected %DATE% CMD variable format (vs DATE /T format) in CMDebug Support 1
P Inserting string into a variable. Support 3
vefatica Setting array variable ignores leading spaces (and @execarray doesn't) Support 4
Joe Caverly Set a batch variable (%1 - %n) when TCC is executing a batch file Support 5
R Difference between TCC and CMD: variable names with hyphens Support 4
Joe Caverly Get a variable type Support 2
M How to set Path variable for non-executable file extensions in 4DOS Support 8
rps For loop internal %_for_files variable? Support 2
A How to safely print variable's value without quotes? Support 9
vefatica Array name in a variable? Support 3
nikbackm TCC 20 variable expansion bug Support 6
X How to set %_INIREAD result to variable Support 5
Charles Dye _USBS variable Support 2
BeechComer Debugger: how to set %1 variable? Support 3
Mordachai Variable followed by function constantly failing... Support 5
T Variable indirection for arrays Support 1
Mike Hall Unexpected "Variable loop" in IF condition Support 10
vefatica If there's no PATH variable ... Support 5
C Maximum length for a variable Support 8
D WAD Internal variable _cpu is undefined Support 2
fpefpe How to? Global variable set /v Support 4
I Change value of a variable while debugging Support 3
I "IF" command in a variable does not expand redirection variable name Support 0
J Variable setting regression in tcc17 ? Support 5
Jay Sage WAD Variable _LOGFILE Not Working Support 2
D Fixed Change in behavior of variable expansion between 16 and 17 Support 3
rps Fixed Using last argument variable ! Support 5
Jay Sage Brackets Around Variable Names Support 11
D Internal variable _tctabs within TCExit Support 9
J Set environment variable from stdout of command Support 3
nickles Passing a variable to a command w/o adding it to the local environment Support 7
nickles WAD Variable name gets changed within FOR loop Support 2
nikbackm FUNCTION with variable number of arguments Support 17
rfaquino WAD Apparently a bug when expanding environment variable %ProgramFiles(x86) Support 2

Similar threads