KyLeCoOl
KyLeCoOl

Reputation: 37

Why am I getting "The following usage of the path operator in batch-parameter substitution is invalid: %~fA"?

When I run my batch file, which contains :

@echo off
for /f "tokens=*" %%A in ('dir %temp% /b /a-d') do (
    echo File Name : %%A, In Folder : %~fA
    )

I keep getting the error :

C:\Users\Dell User\Desktop>filename.bat
The following usage of the path operator in batch-parameter
substitution is invalid: %~fA


For valid formats type CALL /? or FOR /?
The syntax of the command is incorrect.

Why am I getting this error and how can I fix it?

Upvotes: 0

Views: 1386

Answers (1)

IWick
IWick

Reputation: 48

For loops are different from just running commands as the % sign means something else in a for loop. So you have to always escape it with another % sign.

Your code right now is telling Windows command processor that all of the text after %~fA is a variable.

If you want to use a variable in it then make always sure to close it with another like this %%~fA.

Upvotes: 2

Related Questions