Yesterday I had seen question concerning how to get file space information. I tried command like this:
FOR /F %%A IN (‘dir c:\ ^| findstr /rc:Adr’) DO
echo A:”%%A”B:”%%B”C:”%%C”D:”%%D”
I thought it could be possible to extract last line, starting in my local language by “Adr”, yours probably “Directory”. It is not exactly the same because yesterday I got as output result the command itself: dir c:\ ^| findstr /rc:Adr. Now I test it again in CMD and got this:
C:\>FOR %A IN (dir c:\ ^| findstr /rc:Adr) Do Echo A:"%A"B:"%B"C:"%C"D:"%D"
C:\>Echo A:"dir"B:"%B"C:"%C"D:"%D"
A:"dir"B:"%B"C:"%C"D:"%D"
C:\>Echo A:"c:\"B:"%B"C:"%C"D:"%D"
A:"c:\"B:"%B"C:"%C"D:"%D"
C:\>Echo A:"|"B:"%B"C:"%C"D:"%D"
A:"|"B:"%B"C:"%C"D:"%D"
C:\>Echo A:"findstr"B:"%B"C:"%C"D:"%D"
A:"findstr"B:"%B"C:"%C"D:"%D"
C:\>Echo A:"/rc:Adr"B:"%B"C:"%C"D:"%D"
A:"/rc:Adr"B:"%B"C:"%C"D:"%D"
C:\>FOR %A IN ('dir c:\ ^| findstr /rc:Adr') Do Echo A:"%A"B:"%B"C:"%C"D:"%D"
C:\>Echo A:"'dir"B:"%B"C:"%C"D:"%D"
A:"'dir"B:"%B"C:"%C"D:"%D"
C:\>Echo A:"c:\"B:"%B"C:"%C"D:"%D"
A:"c:\"B:"%B"C:"%C"D:"%D"
C:\>Echo A:"|"B:"%B"C:"%C"D:"%D"
A:"|"B:"%B"C:"%C"D:"%D"
C:\>Echo A:"findstr"B:"%B"C:"%C"D:"%D"
A:"findstr"B:"%B"C:"%C"D:"%D"
C:\>Echo A:"/rc:Adr'"B:"%B"C:"%C"D:"%D"
A:"/rc:Adr'"B:"%B"C:"%C"D:"%D"
C:\>dir c:\ | findstr /rc:Adr
Adresářů: 6, Volných bajtů: 1 447 161 856
C:\>
Next situation that I have problem with:
If I want to print filenames:
@Echo off
FOR %%F IN (dir *.inf) DO (
echo %%F
)
First item in the output is dir and then the files. What I do wrong not to obtain the command itself, but the data I requested?
To iterate through lines returned by another command you need to use for command with /f switch. Take a look at
for /?for detailed information.To obtain the amount of free disk space on a computer with Chech version of Windows, use:
for /f "tokens=4,*" %%A in ('dir c:\ ^| findstr /rc:Adr') do echo %%BIf you want a language-independant solution, use:
In the second case, you can omit the dir command and iterate through files directly:
for %%A in (*.inf) do echo %%A