By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

How to? Enumerate files containing '%'

How can this be explained (in a BTM file):

dir *^%*
for %i in (*^%*) do echo %i

The result is (there's only one file - the one listed below - in the working directory):

28.03.2012 10:52 0 àsdf (%23%39).pdf

I would have expected the same file showing up twice.

If it's "WAD", how would I accomplish enumerating all files in the current directory containing percent signs?
In the command, when selecting files, use %% instead of <EscapeChar>%. This is enough in the DIR command, and it will also report the file in the FOR ... ECHO command. However, in the latter, evaluating %i still has trouble. The FOR set the value of i to be the exact filename, %-signs included. However, the ECHO %i tries to evaluate the value of %i; at that point % signs in the filename itself are interpreted as introducing a variable name. A second % indicates the end of the variable name. If that string is numeric (e.g. %23%39) and you are executing a command at the command prompt, it will not be interpreted (unless you defined an environment variable with its name that number, e.g., set 23=goofed23goof). But if the command is executed in a batch file, OR if it is an alias, %23% is replaced with the value of the 23rd batch file or alias parameter, likely to be an empty string, so %23%39 will most likely be displayed as just 39! SETDOS /X-4 solves this problem, but using the variable %i as the parameter of another batch file or alias might still give you problems. Even Charles Dye's safechars.dll is not always capable to deal with % signs embedded in data. The command that worked here is this:
     for %i in (*%%*) echo %@safeexp[i]

Thanks for your support. As there is no solution based on TCC, I've implemented some - yet incomplete - solution for my problem in Perl...

Similar threads