1.

Solve : Batch to find files with todays date time stamp?

Answer»

Looking for a way to find all files edited or created for a specific day such as all with todays date or yesterdays date time stamp when file name and extension is unknown.

Does anyone know of a way to do this in a batch and can show how this can be done with a code snippet etc.

I was thinking of passing the date to search for to a variable and then use that variable in the argument to get the results and if too difficult to show a list of found files, maybe copy the files to a folder at say C:\Recent_Files so I can then go to that folder and look through the contents of what was created or edited for that specific date.

I know that this can be done using the Windows Search feature with wild cards *.* but is there a way to do this at the DOS level?

Thanks in advance for your assistance What's the format of your Dir output? Does the date appear on the LEFT as Day YYYY/MM/DD or some other format? Hey Dusty thanks for responding to assist...

The format is MM/DD/YYYY
Yo Dave. The following code will probably do what you want provided that the date shown in your DIR listing is in dd/mm/yyyy format and appears at the left-hand side of the Dir listing.

It's currently set to find files in your %temp% folder, I did this as a trial only. If you want to search a complete PARTITION change the %temp% in two FOR commands to whatever you want. The FOR commands are:

for /f "delims=*" %%A in ('dir /s/b/tw/a-d %temp%') do (
for /f "delims=*" %%A in ('dir /s/b/tc/a-d %temp%') do (

but be aware that searching an entire partition could be a lengthy process, to search my system partition took 20 mins.

The search date you enter is the date of the files you want to find.

Code: [Select]@echo off
cls
setlocal enabledelayedexpansion



echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.
set/p searchdate= Enter search date (ddmmyyyy):
cls

for /f "tokens=%searchdate:~2,2%" %%F in ("Jan Feb Mar Apl May Jun Jul Aug Sep Oct Nov Dec") do (
set search=%searchdate:~0,2% %%F %searchdate:~-4%
)


echo Files created on %search% = >%temp%\files.txt
echo --------------------------->>%temp%\files.txt
:: echo Files updated on %search%>%temp%/files_updated.txt
:: echo --------------------------->>%temp%files_updated.txt

echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.
echo Please wait - searching for files created on %search%



:: THE FOLLOWING SET FILEDATE COMMANDS SET A VARIABLE ACCORDING TO THE
:: FORMAT OF THE DATE, WHICH YOU STATE TO BE MM/DD/YYYY, AND WHICH
:: MUST APPEAR IN THE LEFT-MOST COLUMN IN YOUR DIR LISTING...



for /f "delims=*" %%A in ('dir /s/b/tc/a-d %temp%') do (
set fdate=%%~tA
set filedate=!fdate:~3,2!!fdate:~0,2!!fdate:~6,4!
if "!filedate!"=="!searchdate!" echo %%~fA>>%temp%\files.txt
)

echo.&echo.
echo PRESS any key to continue...
pause > nul

cls
echo.>> %temp%files.txt
echo Files updated on %search% = >> %temp%files.txt
echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.
echo Please wait - searching for files updated on %search%

for /f "delims=*" %%A in ('dir /s/b/tw/a-d %temp%') do (
set fdate=%%~tA
set filedate=!fdate:~3,2!!fdate:~0,2!!fdate:~6,4!
if "!filedate!"=="!searchdate!" echo %%~fA>>%temp%\files.txt
)

echo.&echo.
echo Press any key to continue...
pause > nul
cls

type %temp%\files.txt | more
echo.&echo.
echo Press any key to exit...
pause > nul
cls

exit/b
[code]

Good luck.[/code]Ok...I'll give it a try on my system and report back if I have any problems or further questions.

Thanks SO MUCH for putting that together... Happy New Years!!! Hey...AWESOME...It works...only glitch I had was failing to read the request of the format of DD/MM/YYYY and I was entering the search as MM/DD/YYYY...after entering 30122008 for 12/30/2008 at the search prompt it worked perfect as shown below.

2 Thumbs UP ... Thanks SO MUCH ... BETTER than I expected and so happy... Now I can hunt down those files....

Now I just need to change focus to search entire drive vs %temp% which is easy..

Have a happy new years!!!


Files created on 30 Dec 2008 =
---------------------------
C:\DOCUME~1\tmpmadn\LOCALS~1\Temp\mProjector957005698\Flash6MovieV2.3.0.9k.mvx
C:\DOCUME~1\tmpmadn\LOCALS~1\Temp\mProjector957005698\FlashPlayer.3.1.0b.ocx
C:\DOCUME~1\tmpmadn\LOCALS~1\Temp\mProjector957005698\mPlayer.3.1.0b.dll
C:\DOCUME~1\tmpmadn\LOCALS~1\Temp\mProjector957005698\System.3.0.9k.mfx
C:\DOCUME~1\tmpmadn\LOCALS~1\Temp\mProjector957005698\Flash6MovieV2.3.0.9k.mvx
C:\DOCUME~1\tmpmadn\LOCALS~1\Temp\mProjector957005698\FlashPlayer.3.1.0b.ocx
C:\DOCUME~1\tmpmadn\LOCALS~1\Temp\mProjector957005698\mPlayer.3.1.0b.dll
C:\DOCUME~1\tmpmadn\LOCALS~1\Temp\mProjector957005698\System.3.0.9k.mfx



Press any key to exit...
Thanks for coming back to report your success.

Happy New Year to you and yours.

D.Looking over code to take it all in in how it works and saw what might be a typo...should it be APR instead of APL for April?

for /f "tokens=%searchdate:~2,2%" %%F in ("Jan Feb Mar Apl May Jun Jul Aug Sep Oct Nov Dec") do (
set search=%searchdate:~0,2% %%F %searchdate:~-4%

Thanks

-- Modified Note: I probably should have just searched for files created in April and see if it worked and if not switch to APR instead of APL...sorry if this is a stupid post...still waking up from last night new years celebration and aftermath...lolUmmm no! Those are wots called literals or parts of a string, searching is not done by month alpha names. The For loop simply extracts the alpha name of the month from the list ("Jan Feb Mar ....etc") based on the numeric month which you entered.

Quote

for /f "tokens=%searchdate:~2,2%" %%F in ("Jan Feb Mar Apl May Jun Jul Aug Sep Oct Nov Dec") do (
set search=%searchdate:~0,2% %%F %searchdate:~-4%

I included this to just pretty up the report - you will note that the header line on the report you posted Quote
Files created on 30 Dec 2008 =
---------------------------
C:\DOCUME~1\tmpmadn\LOCALS~1\Temp\mProjector957005698\Flash6MovieV2.3.0.9k.mvx
C:\DOCUME~1\tmpmadn\LOCALS~1\Temp\mProjector957005698\FlashPlayer.3.1.0b.ocx
says "Files created on 30 Dec 2008", well Dec comes from that list of months. The search for files is done purely on the date in the format ddmmyyyy (e.g. 20122008).

Try changing the months Jan Feb.. etc to something else like Nub Rub Sub Nanny etc... and check the report header, files created/updated on the date you enter will still be listed.Ok...got it!

Now that makes sense...

BTW any suggestions of a good book to learn batch programming?

Been just learning hands on by looking at everyone elses code etc and tweaking it to understand it sort of a reverse engineering of how it functions.

I know Basic, C++, and a few other languages and Batch is different, but like any other scripting language structured in its own way. With enough practice maybe some day I will be as good as you experts...lol

Thanks again


Discussion

No Comment Found