[OT]: Count files with DIR and write to file

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
User avatar
Peter
Power Member
Power Member
Posts: 2068
Joined: 2003-11-13, 13:40 UTC
Location: Schweiz

[OT]: Count files with DIR and write to file

Post by *Peter »

Hi

in another posting I got this code ("DOS" - CMD)

Code: Select all

dir "c:\Tasks\*.tmp" /b /s |find /v /c "::" > c:\temp\tmpcount.txt
This counts all TMP-files in folder c:\tasks and writes the results to the file c:\temp\tmpcount.txt; e.g.

Code: Select all

10
Using a second command appends the second result to the same file

Code: Select all

dir "c:\Tasks\*.txt" /b /s |find /v /c "::" >> c:\temp\tmpcount.txt
Result:

Code: Select all

10
12
This is wonderful and fine, but here is my simple question:
How to write both results in one(1) line?

Code: Select all

10 / 12
Thanks and regards

Peter
TC 10.xx / #266191
Win 10 x64
User avatar
TLis
Member
Member
Posts: 111
Joined: 2004-06-02, 16:48 UTC
Location: Szczecin, Poland

Post by *TLis »

Code: Select all

dir "c:\Tasks\*.tmp" /b /s |find /v /c "::" > c:\temp\1.txt
for /F %%i in (C:\temp\1.txt) do set q1=%%i

dir "c:\Tasks\*.txt" /b /s |find /v /c "::" >> c:\temp\2.txt
for /F %%i in (C:\temp\2.txt) do set q2=%%i

echo %q1% / %q2% > C:\Users\stn_tli\Desktop\tmpcount.txt
del C:\temp\1.txt
del C:\temp\2.txt
User avatar
Stefan2
Power Member
Power Member
Posts: 4281
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Post by *Stefan2 »

Great stuff!

So i got this idea based on yours:

Code: Select all

for /F  %%i in ('dir C:\Task\*.tmp /A-D /S ^|find "::" /v /c') DO @SET out=%%i
for /F  %%i in ('dir C:\Task\*.txt /A-D /S ^|find "::" /v /c') DO @SET out=%out% / %%i
for /F  %%i in ('dir C:\Task\*.bak /A-D /S ^|find "::" /v /c') DO @SET out=%out% / %%i
e.t.c.

echo %out%
3 / 11 / 7

echo %out% > c:\temp\tmpcount.txt
User avatar
Peter
Power Member
Power Member
Posts: 2068
Joined: 2003-11-13, 13:40 UTC
Location: Schweiz

Post by *Peter »

@TLis
Dziekuje bardzo za pomoc, pozdrowienia do Szczecina.

@Stefan2
Danke für die Hilfe, Grüse nach D.

Thanks to all.

Peter
TC 10.xx / #266191
Win 10 x64
Post Reply