Microsoft says: "%~fI expands %I to a fully qualified path name"
this is a bit misleading, as it looks like it will represent the full pathname of the file. However this is not true.
Actually this is the current folder + filename!
It represents the pathname of the folder where the FOR command is executed, followed with the filename, which may be different.
Just give it a try:
Imagine you have file:
now do this:
c: cd \f1\f2 FOR /F %G in ('dir /b C:\f1\f2\f3\ff.txt') do echo %~fG
this returns C:\f1\f2\ff.txt to me, i.e. f3 is missing!
What do you think?
"dir /b" only the file name so it's normal.
if you try with "dir /b /s" it will be the full path will be returned.
you can try something like this
for %a in ("|<>") do @echo %~fa
it will return "c:\current_path\|<>" despite you cant have a file named |<>
I do not think it's normal.
If I understand you, just because dir /b returns no pathname, then it's normal to return the current path instead of the "fully qualified path name"!!??
That's strange behavior in my opinion...
Anyway, this is how it is.
"dir /b" doesn't provide a full path so, with no context, as far as "for /f" is concerned it's just words ... It can't tell you what it doesn't know (it's not working with file descriptors, nor parsing the "dir" command, it's just viewing the output), so it makes a guess at trying to give you what you want based on what little information it has.
If you did "for %a in (C:\f1\f2\f3\ff.txt') do echo %~fG" you should see the full path.
cmd | *sh | Puppet | PowerShell | AutoIT3
Ok thank you bluesxman, this is much clearer. Nothing was telling me that "it's not working with file descriptors" besides of you. I understand "it's just words", ok, however they are really misleading and I do not see what would prevent them to use file descriptors or to write better words.
The "guess", on its side, is unfortunate and too optimistic!
Thank you for your help,