Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7092773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:21:22+00:00 2026-05-28T08:21:22+00:00

I apologize if this question was already asked but I can’t seem to find

  • 0

I apologize if this question was already asked but I can’t seem to find exactly what I am looking for. I want to be able to find files in XP (using cmd) that are older than a specific date. I want to do something like DIR/FIND files that are older than 30 days.

The following does not work but hopefully it will give you an idea of what I am trying to do.

FOR /f %%f IN ('DIR /b /t -30 I:\FOLDER1\*.pdf') DO move /Y Z:\FOLDER1\%%f "I:\FOLDER2\"

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T08:21:23+00:00Added an answer on May 28, 2026 at 8:21 am

    Julian date function are taken from DosTips.com function library

    First use XCOPY /L /D to get list of files that have been modified within past 30 days: save to an exclude list.

    Then use XCOPY /L to get all files and pipe through FINDSTR to exclude the files from the exclude list and save results to an include list.

    Finally loop through include list and move the files

    @echo off
    setlocal
    
    set src="I:\FOLDER1\*.pdf"
    set dest="I:\FOLDER2"
    set incl="%temp%\includeFiles%random%.txt"
    set excl="%temp%\excludeFiles%random%.txt"
    
    call :jdate jd
    set /a jd-=30
    call :jdate2date jd yyyy mm dd
    xcopy %src% %dest% /d:%mm%-%dd%-%yyyy% /l | findstr /vxrc:"[0-9]* File(s)" >%excl%
    xcopy %src% %dest% /l | findstr /vxrc:"[0-9]* File(s)" | findstr /vixlg:%excl% >%incl%
    set /a "fail=0, ok=0"
    for /f "usebackq eol=: delims=" %%F in (%incl%) do (
      move /y "%%F" %dest% >nul 2>&1 && (
        echo "%%F"
        set /a "ok+=1"
      ) || (
        >&2 echo ERROR: Unable to move "%%F"
        set /a "fail+=1"
      )
    )
    echo ----------------------
    echo Moved %ok% files
    if %fail% gtr 0 echo Failed to move %fail% files
    del %excl%
    del %incl%
    exit /b %fail%
    
    
    :jdate2date JD YYYY MM DD -- converts julian days to gregorian date format
    ::                     -- JD   [in]  - julian days
    ::                     -- YYYY [out] - gregorian year, i.e. 2006
    ::                     -- MM   [out] - gregorian month, i.e. 12 for december
    ::                     -- DD   [out] - gregorian day, i.e. 31
    :$reference http://aa.usno.navy.mil/faq/docs/JD_Formula.html
    :$created 20060101 :$changed 20080219 :$categories DateAndTime
    :$source http://www.dostips.com
    SETLOCAL ENABLEDELAYEDEXPANSION
    set /a L= %~1+68569,     N= 4*L/146097, L= L-(146097*N+3)/4, I= 4000*(L+1)/1461001
    set /a L= L-1461*I/4+31, J= 80*L/2447,  K= L-2447*J/80,      L= J/11
    set /a J= J+2-12*L,      I= 100*(N-49)+I+L
    set /a YYYY= I,  MM=100+J,  DD=100+K
    set MM=%MM:~-2%
    set DD=%DD:~-2%
    ( ENDLOCAL & REM RETURN VALUES
        IF "%~2" NEQ "" (SET %~2=%YYYY%) ELSE echo.%YYYY%
        IF "%~3" NEQ "" (SET %~3=%MM%) ELSE echo.%MM%
        IF "%~4" NEQ "" (SET %~4=%DD%) ELSE echo.%DD%
    )
    EXIT /b
    
    :jdate JD DateStr -- converts a date string to julian day number with respect to regional date format
    ::                -- JD      [out,opt] - julian days
    ::                -- DateStr [in,opt]  - date string, e.g. "03/31/2006" or "Fri 03/31/2006" or "31.3.2006"
    :$reference http://groups.google.com/group/alt.msdos.batch.nt/browse_frm/thread/a0c34d593e782e94/50ed3430b6446af8#50ed3430b6446af8
    :$created 20060101 :$changed 20090328 :$categories DateAndTime
    :$source http://www.dostips.com
    SETLOCAL
    set DateStr=%~2&if "%~2"=="" set DateStr=%date%
    for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('"echo.|date"') do (
        for /f "tokens=1-3 delims=/.- " %%A in ("%DateStr:* =%") do (
            set %%a=%%A&set %%b=%%B&set %%c=%%C))
    set /a "yy=10000%yy% %%10000,mm=100%mm% %% 100,dd=100%dd% %% 100"
    if %yy% LSS 100 set /a yy+=2000 &rem Adds 2000 to two digit years
    set /a JD=dd-32075+1461*(yy+4800+(mm-14)/12)/4+367*(mm-2-(mm-14)/12*12)/12-3*((yy+4900+(mm-14)/12)/100)/4
    ENDLOCAL & IF "%~1" NEQ "" (SET %~1=%JD%) ELSE (echo.%JD%)
    EXIT /b
    

    I did not use the XCOPY /EXCLUDE option because it treats the files as having implicit wildcards. So if you specified * instead of *.pdf, then an excluded file named TEST would also cause files named TEST1, TEST.TXT, and TEST.EXE to be excluded as well.

    The FINDSTR /I option is required to compensate for a FINDSTR bug when doing a search with multiple literal search strings. The /I option shouldn’t be required, but doing a case sensitive search with multiple literal search strings can give the wrong result.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I apologize if this question was asked already before but I could not find
I apologize if this question has been answered already, but I cannot seem to
First off, I apologize if this question has already been asked. I searched but
Apologies if I missed this question already, but I searched and couldn't find it.
Hopefully no one has asked this question - didn't see it, but I apologize
I apologize if this has already been asked a different way but I couldn't
I apologise if this question has already been asked on here before but I
I apologize if the same question was asked already. I just couldn't find. Please
I'm pretty sure it hasn't, but apologies if this question has already been asked.
Apologies if this question has been asked already, but suppose we have this code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.