[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

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

Search file and folder based on date created

I am looking for a way to find out how to search a partition for all files and folders based on the date range they are created.

For example: I want all folders created between 1/1/2011 and 1/31/2011. How should I go about that?
1 Solution
For 50 points,

1.  Use  DIR to obtain information and store in file
DIR /S /a:d >  C:\folderInfo.txt

2. Manually use MS WORD to "highligh" the dates you want if the number you guess is great
    or fast reading
Bill PrewCommented:
That's going to be very hard (but not impossible, but likely not worth only 50 points) to do in a pure BAT file script.  Batch scripting doesn't have good support for dates, so comparing dates to see if they fall in a range takes more than a few lines of code.

Does this have to be a DOS batch script, or couse a VBS (vb script) solution work, it has much better date comparing capabilities.

dishelpAuthor Commented:
Hello billprew,

Sorry, I'm not sure about the point system before and I wasn't clear on the difficulty. Any suggestion what I should put down for the point value? Any help would be greatly appreciated. I'm fairly new to this :)

As long as it works, we have no preference if it's VBS or DOS Batch.

Thanks in advance.
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

I think that it is very hard, at least 500 points.
Bill PrewCommented:
"For example: I want all folders created between 1/1/2011 and 1/31/2011. How should I go about that?"

So, do you just want a list of the folders?  None of the files contained in them?

Do you have any other needs?


Here is how I would do this.

I did not test it so I'm sure it's buggy

PS: hey bp!


SETLOCAL enabledelayedexpansion

SET OutputFile=%~n0.log
SET DirToScan=C:\Temp

SET DateMin=1/1/2011
SET DateMax=1/31/2011

CALL :ConvertJulian DateMin %DateMin%
CALL :ConvertJulian DateMax %DateMax%

FOR /F "delims=" %%A in ('dir /b /s /ad "%DirToScan%"') DO (
	SET Folderdate=%%~tA
	CALL :ConvertJulian Folderdate !Folderdate!
	IF %Folderdate% GEQ %DateMin% IF %Folderdate% LEQ %DateMax% ECHO %%~fA>>"%OutputFile%"


FOR /F "tokens=1-3 delims=/" %%A IN (%~1) DO (
	SET DayVal=%%B
	SET MonthVal=%%A
	SET YearVal=%%C

	SET /a "YearJ=10000%YearVal% %%10000,MonthJ=100%MonthVal% %% 100,DayJ=100%DayVal% %% 100"
	SET /a %~2=DayJ-32075+1461*(YearJ+4800+(MonthJ-14)/12)/4+367*(MonthJ-2-(MonthJ-14)/12*12)/12-3*((YearJ+4900+(MonthJ-14)/12)/100)/4

Open in new window

Bill PrewCommented:

Awaiting further clarification...


Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

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