There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot browser bsod computer crash css dell desktop driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware help please hijackthis hjt hjt log install internet internet explorer itunes javascript keyboard laptop log malware monitor network networking openoffice outlook outlook 2003 outlook express password popups problem router seo slow sound sp3 spyware startup trojan usb video virtumonde virus vista vundo windows windows xp winxp wireless youtube
DOS/PDA/Other
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Operating Systems > DOS/PDA/Other >
.bat to copy files based on today's date


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
TWC330's Avatar
Computer Specs
Junior Member with 1 posts.
 
Join Date: May 2008
Experience: Intermediate
01-May-2008, 01:14 PM #1
.bat to copy files based on today's date
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's Avatar
Distinguished Member with 12,328 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
01-May-2008, 02:27 PM #2
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's Avatar
Computer Specs
Senior Member with 1,103 posts.
 
Join Date: Feb 2006
Location: The Pitt, BC
Experience: Omnigeek
01-May-2008, 06:45 PM #3
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's Avatar
Distinguished Member with 4,794 posts.
 
Join Date: Apr 2007
Location: India
Experience: Advanced
01-May-2008, 08:46 PM #4
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

Last edited by devil_himself : 01-May-2008 09:05 PM.
TheOutcaste's Avatar
Computer Specs
Senior Member with 1,538 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
03-May-2008, 11:02 PM #5
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
__________________
Of course I know all the answers ; I just don't always match the answers to the right questions

Warning -- Windows spoken here. (Rated R for Strong Language and Violence -- When your Windows PC flies through a window, that's violent, right?)
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 05:25 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.