Ajinkya
Ajinkya

Reputation: 1711

Batch file giving count of files date wise

There are millions of HL7 files coming in network folder. I want to know date wise how many files came to network folder.

I want to create batch file which will give me count of HL7 files date wise.

E.g.

2014-01-27: 458 Files
2014-01-26: 987 Files
2013-10-17: 2308 Files

If above is not possible then It is also ok if it gives me count of text files created/modified/accessed on a particular date present under folder.

E.g.

If I want to know files which were created today it should give me output some what like this:

2014-01-27: 45458 Files

Upvotes: 2

Views: 3700

Answers (3)

MC ND
MC ND

Reputation: 70923

Not as fast as Aacini's or foxidrive's answers, but just to add an option to output the date in the system format, and get the output ordered by date.

@echo off
    setlocal enableextensions enabledelayedexpansion

    set "count=0"
    set "previous="
    for /f %%f in ('dir "%~1" /a-d /tc /od ^| findstr /r /c:"^[^ ]"') do (
        if "!previous!"=="%%f" ( set /a "count+=1" ) else (
            if defined previous echo !previous! : !count!
            set "previous=%%f"
            set "count=1"
        )
    )
    if defined previous echo !previous! : !count!

Upvotes: 1

foxidrive
foxidrive

Reputation: 41234

I didn't want to edit Aacini's answer to add this, but the code below uses his algorithm and could be a little more robust.

@echo off
setlocal EnableDelayedExpansion

for /F %%a in ('dir %1 /a-d ^|findstr "^[0-9]"') do (
   set fileDate=%%a
   set fileDate=!fileDate:/=_!
   set fileDate=!fileDate:-=_!
   set /A Files[!fileDate!]+=1
)
set Files[
pause

Upvotes: 2

Aacini
Aacini

Reputation: 67216

The Batch file below is a preliminary version; we will modify it as you confirm this is what you want. It assume that the separator in date fields displayed in dir command is a dash; if it is not, just replace the right separator in this line: set fileDate=!fileDate:-=_! (before the equal-sign).

@echo off
setlocal EnableDelayedExpansion

for /F %%a in ('dir %1') do (
   set fileDate=%%a
   set fileDate=!fileDate:-=_!
   if "!fileDate!" neq "%%a" set /A Files[!fileDate!]+=1
)
set Files[

You may insert /T switch in the parameter in order to select the type of desired date; see dir /? for details.

Upvotes: 3

Related Questions