1

I found an answer here: How can I check the size of a file in a Windows batch script? and it works well if the file path is without spaces but not if it has spaces

Example:

set file=C:\Example.txt
FOR /F "usebackq" %%A IN ('%file%') DO set size=%%~zA

works but

set file=C:\Program Files\Example.txt
FOR /F "usebackq" %%A IN ('%file%') DO set size=%%~zA

not, I tried to double quote the path in variable declaration

set file="C:\Program Files\Example.txt"

and/or in FOR loop file variable

FOR /F "usebackq" %%A IN ('"%file%"') DO set size=%%~zA

but none works

Community
  • 1
  • 1
Effedieffe
  • 11
  • 1
  • 1

1 Answers1

2
set "file=C:\Program Files\Example.txt"
for %%A in ("%file%") do set "size=%%~zA"

There is no need for a for /f command (its normal use is to process file contents or strings or the output of command execution), a basic for command to grab a reference to a file will be enough.

MC ND
  • 69,615
  • 8
  • 84
  • 126