# .bat to copy files based on today's date



## TWC330

i have a directory whose file names happen to begin with today's date, for example 501*.txt. i have a bat file that copies these files based on 501*.txt. (xcopy c:\temp\501*.*) but i have to modify the date in the bat file each time before running the bat file. 

how do get the bat file to check for today's date first, then go out and copy files based on the last date modified? in other words, there may be files that were modified three days ago in this directory, but i don't want to copy them. i want the bat file to get today's date, then go out and copy files that are equal or greater than today's date. 

best regards!


----------



## Squashman

You may want to look at XXcopy. I believe it can do this natively. Been a while since I used ti. I know you will get an answer to your problem today though from someone who knows batch files better than me.

http://www.xxcopy.com/index.htm


----------



## Soundy

4DOS/4NT has an advanced COPY command that can do a similar task as well - you can specify a date or a range of dates for COPY, MOVE, DELETE, or any other number of standard file functions.

www.jpsoft.com


----------



## devil_himself

Code:


::Copy Files Made Or Modified Today
@echo off
setlocal
set source=c:\src
set dest=c:\dest
pushd "%source%"
for %%f in ('dir /b /a-d') do (
    echo "%%~tf" | find "%date%" > nul && copy "%%~ff" "%dest%"
    )
  endlocal & goto :EOF

Note -- > Untested

-----------------------------------OR----------------------------------------------



Code:


::Copy Files Made Or Modified Today
@echo off
setlocal
set source=c:\src
set dest=c:\dest
pushd "%source%"
set t=%date:~4%
for /f %%a in ('dir /b /a-d /o-d') do call :PROCESS "%%a"
goto :eof
popd

:PROCESS
for /f %%j in ('echo %~t1') do set d=%%j
if "%d%"=="%t%" copy %1 "%dest%"
goto :eof

Note -- > Untested


----------



## TheOutcaste

This should work. This is based on US date format using leading zeros for month and day, i.e., %date% returns *Sat 05/03/2008*
Open a command prompt and type echo.%date% to see what your format is.

If it's different, paste your setting here and I can adjust the file if need be.



Code:


for /f "tokens=2,3 delims=/ " %%I in ("%date%") do Set _Month=%%I& Set _Date=%%J
Set _Month=%_Month:0=%
xcopy c:\temp\%_Month%%_Date%*.txt

HTH

Jerry


----------

