Batch Files

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

da1i1princess

Thread Starter
Joined
Nov 8, 2007
Messages
3
I know it's archaic.

Here's my dilemma...I've got an archive folder that has files dating back from 2006. I want to create a batch file to copy the most recently dated files to another folder called Daily. This would run each day.

Is it possible to denote that??? :confused:

Here is an example of my script:

copy "c:\TEST\site\archives\*.*" %GOTO CUR-DATE% "C:\TEST\site\Daily" /y

I've tried to run it several times and it just copies "all" the files in the archive folder over.

Thanks to whomever can help me.
 
Joined
May 11, 2007
Messages
56
If this is a Windows system you can use XCOPY to do this by using the /D:m-d-y to specify copying only those files modified or created on or after the specified date. For example to copy only those files created or changed today you could specify:

xcopy "c:\TEST\site\archives\*.*" "C:\TEST\site\Daily" /d:11-08-2007

John Hensley
www.resqware.com
 

da1i1princess

Thread Starter
Joined
Nov 8, 2007
Messages
3
Thanks John for replying. Yes, it is a Windows system. I have tried your suggestion and that does work...but I'm lookin for a script that would automatically pull the current file vs. me actually having to put in a date. I have to pull files daily and this would make life a whole lot simpler.

Do you know a way that I can accomplish this?
 

da1i1princess

Thread Starter
Joined
Nov 8, 2007
Messages
3
I've been googlin my topic and I think this might work...I just don't know how to rewrite it to fit what I need.

:: CTULD.bat
:: Copies Files Modified or Created Today
:: to the Upload Directory, or Copies
:: from the Specified Date Forward
::
@ECHO OFF
If no Date is Given, Today's
IF "%1" == "" GOTO COPY-TODAY Files will be Copied
IF NOT "%1" == "" GOTO COPY-DATE Otherwise, Files will be Copied
Forward of the Date Typed

:COPY-TODAY (See Text, Below)
ECHO. | DATE | FIND /I "Current" > C:\BATCH\CUR-DATE.BAT
ECHO @SET CUR-DATE=%%4 > C:\BATCH\CURRENT.BAT
CALL C:\BATCH\CUR-DATE.BAT

XCOPY *.* C:\UPLOAD /D:%CUR-DATE% < NUL Copies Files based on
Today's Date
("NUL" Hides Screen Messages)
GOTO END

:COPY-DATE Copies Files based on
XCOPY *.* C:\UPLOAD /D:%1 /-Y The Date Given at the
Command Line
:END
ECHO. Separates the Listing
CALL C:\BATCH\DR.BAT C:\UPLOAD Gives a Listing for the
UPLOAD Directory to
Show the Operation's Success

SET CUR-DATE= Removes the Date Variable
From the Environment

DEL CUR-DATE.BAT Deletes the
DEL CURRENT.BAT Temporary Batch Files
 
Joined
May 11, 2007
Messages
56
If you are using Windows 2K or later this should work.

@ECHO OFF
REM Create TODAY environment variable in the format mm-dd-yyyy
FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET TMPDATE=%%B
FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET mm=%%B
FOR /F "TOKENS=1,2 DELIMS=/ eol=/" %%A IN ('echo %TMPDATE%') DO SET dd=%%B
FOR /F "TOKENS=2,3 DELIMS=/ " %%A IN ('echo %TMPDATE%') DO SET yyyy=%%B
SET TODAY=%mm%-%dd%-%yyyy%
REM Copy the files with today's date
xcopy "c:\TEST\site\archives\*.*" "C:\TEST\site\Daily" /d:%TODAY% /y
REM Delete evironment variables
SET TMPDATE=
SET dd=
SET mm=
SET yyyy=
SET TODAY=
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top