Re: some absurdities w/ if exist and escaping with caret and
where can I read about "path normalization" specifically, "path normalization" in the dos prompt or msdos?
Normalization is a word in math terms that means, a specific representation. In this case normalization is
just the transformation of an arbitrary path to the Fully Qualified Path. I'm sure you can do this intuitively,
if not see the rules at the url, i've given above. The quotes and escape sequences are replaced by the
command line interpreter itself, but the resulting string is handled as one token. So the path normalization
is done on a 'normal' string. The normalization is done on the string and the current directory value, that is
tracked by the system only, it doesn't check any existance of pathes, files, ... :
Z:\>dir "i bet this path does not exist, but that doesn't matter even if it contains these characters: \/:*?""<>| \..\..\." /B
I guess the quotes make any reference to the nul device, literal in the sense that now it will look only for file objects and not the nul device?
I'm not sure if that is true, it may be, but i won't bet on it; the paragraph Namespace in the given link is a little bit diffuse.
If there is more information available it can surely be found in some MS C++ documentation.
I would handle it in this way, as the namespaces of nul may be linked explicitely to a folder:
Nul doesn't work reliably as a test for directories.
Edit:This means don't use nul, com1, ... within filenames.
If so, how can the unexpected result in exhibit d be explained?exhibit d
C:\crp>if exist "c:\crp\nul" echo yeah <--- expected
C:\crp>copy con nul
1 file(s) copied.
C:\crp>if exist "c:\crp\nul" echo yeah <-- unexpected
The program copy.exe, or a functionality called by copy.exe, may be able to set, unset,
link, unlink, hide, ... namespaces and symbolic links visible to each file system object.
Or it is a result of how windows handles namespaces mentioned in the second point,
directly above, don't know.
this one below seems strange, I don't know what the tokenization is. I would expect the ^ preceding the space, to have the same
effect as " " and so I would have expected one token [c:\ab cde\a(b)c] and thus I would expect it to see my directory.exhibit c -improved
C:\ab cde\a(b)c>if exist c:\ab^ cde\a(b)c echo yeah <--- unexpected. i would expect yeah to be echoed.
No your expectation is wrong: I've posted it above. The tokenization is done after ^SPACE is replaced by a SPACE only.
Here is a small batch that should display the tokenization:
if "%~2" == "" goto :last
set /P "=[%1] " < nul
if not "%~2" == "" goto loop
Then just use it:
Z:\>tokenize if exist c:\ab^ cde\a(b)c echo yeah
[if] [exist] [c:\ab] [cde\a(b)c] [echo] [yeah][if] [exist] [c:\ab] [cde\a(b)c] [echo] [yeah]