Search file and folder based on date created

Posted on 2011-04-28
Last Modified: 2012-05-11
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?
Question by:dishelp
    LVL 4

    Expert Comment

    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
    LVL 51

    Expert Comment

    by:Bill Prew
    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.


    Author Comment

    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.

    Expert Comment

    I think that it is very hard, at least 500 points.
    LVL 51

    Expert Comment

    by:Bill Prew
    "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?


    LVL 10

    Accepted Solution

    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
    EXIT /b

    Open in new window

    LVL 51

    Expert Comment

    by:Bill Prew

    Awaiting further clarification...


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
    One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now