# SS64 Forum

You are not logged in.

## #1 21 Dec 2016 15:15

stefano.gatto
Member
From: Geneva, Switzerland
Registered: 26 Nov 2014
Posts: 5

### %~fI expands %I to a fully qualified path name???

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:

C:\f1\f2\f3\ff.txt

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?

Offline

## #2 21 Dec 2016 15:52

npocmaka
Member
From: Bulgaria
Registered: 03 Dec 2009
Posts: 421

### Re: %~fI expands %I to a fully qualified path name???

"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 |<>

Offline

## #3 21 Dec 2016 16:53

stefano.gatto
Member
From: Geneva, Switzerland
Registered: 26 Nov 2014
Posts: 5

### Re: %~fI expands %I to a fully qualified path name???

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.

Offline

## #4 22 Dec 2016 16:55

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 1,033

### Re: %~fI expands %I to a fully qualified path name???

"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 | Ruby | Chef | Puppet | PowerShell | AutoIT3

Offline

## #5 06 Jan 2017 10:31

stefano.gatto
Member
From: Geneva, Switzerland
Registered: 26 Nov 2014
Posts: 5

### Re: %~fI expands %I to a fully qualified path name???

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,
Stefano

Offline

## Board footer

Powered by FluxBB