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