• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 288
  • Last Modified:

Script to count each type of ext files

Hi,

Need a scrfipt to count each type of file.EX:
I have a folder which has 1000's of different types of file ext jpeg,gif,dat.

Results a

Jpeg:100
gif:87
dat:900

Etc

Regards
Sharath
0
bsharath
Asked:
bsharath
  • 2
  • 2
1 Solution
 
Farhan KaziSystems EngineerCommented:
:: Successful run will generate ExtCount.txt file
@Echo Off
SetLocal EnableDelayedExpansion

IF EXIST ExtCount.txt DEL /F /Q ExtCount.txt
SET LastExt=
FOR /F "delims=*" %%E IN ('Dir *.* /B /OE') DO (
      IF NOT "!LastExt!"=="%%~xE" (
            Echo Counting: %%~xE
            FOR /F %%f IN ('Dir *%%~xE ^| FIND /I "File(s)"') DO (Echo %%~xE:%%f >>ExtCount.txt)
      )
      SET LastExt=%%~xE
)
0
 
bsharathAuthor Commented:
I get this.

.bat:5
.BAT:5
.bat:5
.cmd:3
.exe:3
.log:1
.SYS:1
.txt:5

Where is this script searching and can i have the file names and paths.
0
 
Farhan KaziSystems EngineerCommented:
Check following, also try running inside folder.

:: Successful run will generate ExtCount.txt file
@Echo Off
SetLocal EnableDelayedExpansion
IF EXIST ExtCount.txt DEL /F /Q ExtCount.txt
SET LastExt=
FOR /F "delims=*" %%E IN ('Dir *.* /B /OE') DO (
      IF /I NOT "!LastExt!"=="%%~xE" (
            Echo Counting: %%~xE
            FOR /F %%f IN ('Dir *%%~xE ^| FIND /I "File(s)"') DO (Echo %%~xE:%%f >>ExtCount.txt)
      )
      SET LastExt=%%~xE
)
0
 
bsharathAuthor Commented:
I get this when i run in the windows folder.

.avi:1
.BAK:1
.bat:1
.bin:1
.bmp:11
.dat:1
.dll:22
.EXE:16
.INI:11
.log:79
.msp:3
.NET:0
.old:1
.pif:1
.prx:1
.scf:1
.tmp:4
.txt:14
.url:1

Thanks a lot...
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now