0

The requirement is that I have 1 folder and in that folder there are so many txt files, and everyday 100s of files landed and processed, now I want to monitor how many files are present on the folder at the moment when I run the bat file for today's date.

Below is the script I have been using, but seems it is working but fetching all the document instead of today's document only

@echo off
setlocal enabledelayedexpansion
set c1=0
    for  /f "tokens=*" %%x in ('dir /s /a /b "D:\Flow\Flow1\Flow2\Flow3\KEN*.txt" 2^>nul') do set /a c1+=1

echo.KEN,!c5!
4
  • 2
    Try dir /s /a "D:\Flow\Flow1\Flow2\Flow3\*.txt" 2>NUL | find /C "%date%" Commented Oct 30, 2017 at 11:21
  • Giving me error, not working fine Commented Oct 30, 2017 at 14:17
  • Please edit your question and add a minimal reproducible example instead of useless "giving me error", "not working fine" or "not working at all" enunciation. Questions seeking debugging help ("why isn't this code working?") must include the desired behaviour, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement (and error code/message) are not useful to other readers. Commented Oct 30, 2017 at 16:44
  • 1
    @RishabhBhargav, you have completely failed to answer the questions raised as a result of your opening comment to my answer. In your question, please try to explain what, I don't think i can create a robocopy in the Production, this is working in UAT but not an option for me is supposed to mean? What are Production and UAT? and what is stopping you using the RoboCopy command? Commented Nov 1, 2017 at 10:16

2 Answers 2

0

Is this what you mean?


From the Command prompt:

(For /F %A In ('Dir/S/W/A-D-S-L "D:\Flow\Flow1\Flow2\Flow3\NGR*.txt" 2^>Nul') Do @Call Set "fC=%dC%"&Set "dC=%A")&Call Echo(%fC%

From a batch file:

@Echo Off
SetLocal EnableDelayedExpansion
Set "dC="
For /F %%A In ('Dir/S/W/A-D-S-L "D:\Flow\Flow1\Flow2\Flow3\NGR*.txt" 2^>Nul'
) Do Set "fC=!dC!"&Set "dC=%%A"
Echo %fC%
Pause

You could optionally include %DATE% @ %TIME% on line 5 too.

Sign up to request clarification or add additional context in comments.

5 Comments

I don't think i can create a robocopy in the Production, this is working in UAT but not an option for me
if you can give me any other option
If you have important information relevant to your question, I'd suggest you edit your question to include it!
I have recreated the code above after re-reading your question and seeing a completely different task. Is this now a closer solution?
I have changed my question and clear my query, hope this may help you to understand and help me out with the query
0

a convenient command to find files "created today" is the forfiles command (not used very often, probably because of its counter-intuitive syntax and some oddities). Pipe it to find /c to get the count, put a for /f around it and you're done:

set "days=0"
REM 0 for "created zero days ago" = "created today"
set count=0
REM for /f %%x in ('forfiles /D %days% /P "D:\Flow\Flow1\Flow2\Flow" /m "KEN*.txt" ^|find /i /c ".txt"') do set count=%%x
echo KEN,%count%

set days to 3 to get files newer than three days (today and the two days before) - may be useful on Mondays.

("zero days old" means "today" (not the last 24 hours, but since 00:00) - just one of it's oddities)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.