From FOR /?
:
In addition, substitution of FOR variable references has been enhanced.
You can now use the following optional syntax:
%~I - expands %I removing any surrounding quotes (")
%~fI - expands %I to a fully qualified path name
%~dI - expands %I to a drive letter only
%~pI - expands %I to a path only
%~nI - expands %I to a file name only
%~xI - expands %I to a file extension only
%~sI - expanded path contains short names only
%~aI - expands %I to file attributes of file
%~tI - expands %I to date/time of file
%~zI - expands %I to size of file
%~$PATH:I - searches the directories listed in the PATH
environment variable and expands %I to the
fully qualified name of the first one found.
If the environment variable name is not
defined or the file is not found by the
search, then this modifier expands to the
empty string
I've run a Windows batch script that does @echo %~aI %~fI ^<%~zI byte^(s^)^>
in a FOR
loop looping through directories (the path of each of which gets stored in %I
) and got this output:
d--hs------ J:\$RECYCLE.BIN <0 byte(s)>
d---------- J:\Multimedia <4096 byte(s)>
dr--------- J:\-C-\……\Desktop <12288 byte(s)>
dr--------- J:\-C-\……\Documents <28672 byte(s)>
dr--------- J:\-C-\……\Downloads <81920 byte(s)>
Those “sizes” of the directories above have nothing to do with those of the files in them. What exactly does it mean by a “size” from %~zI
? Were %I
a normal file, it would be the size of it. But what if %I
is a directory? I can't quite grasp it. Is it really meaningless?