1.

Solve : Compare file date to system date and copy to archive?

Answer»

Hi team,

I've created a batch file which sets off a series of processes.
I want to add a line into the batch file to test if the date of the file is today. If not then stop processing.

At the end of the batch, I want to copy SPECIFIED FILES to archive.

How would I go about these two requirements?

Cheers
Bernard
How is the file named? like: 03-26-2009.txt
Quote from: macdad- on March 26, 2009, 06:21:20 AM

How is the file named? like: 03-26-2009.txt


I believe it's a file creation date that he wants to check, not a file name, but of which file it isn't clear.for today date, there is no need to ask for user system date format, check the FOLLOWING and you will understand.

Code: [Select]+C:\>echo %date%
Thu 03/26/2009

+C:\>echo %date:~-10%
03/26/2009

+C:\>set d=>file.txt & for %a in (file.txt) do @set d=%~ta & echo %~ta & call echo %d:~0,10%
03/26/2009 08:50 PM
03/26/2009

the %~ta in for loop output MODIFIED date i believe. so for creation date, using dir command is one of the method.Quote from: Reno on March 26, 2009, 07:53:40 AM
the %~ta in for loop output modified date i believe. so for creation date, using dir command is one of the method.

It returns file creation date on my system

Also, date string will be different in non-US locales.
now i set my regional setting to albanian:

Code: [Select]+C:\>echo %date%
2009-03-26

+C:\>echo %date:~-10%
2009-03-26

+C:\>set d=>file.txt & for %a in (file.txt) do @set d=%~ta & echo %~ta & call echo %d:~0,10%
2009-03-26 09:08MD
2009-03-26

we only need to check for equality of 10char string here. no math involved, and no yy mm dd parsing.
only works for today date though, except bulgarian.Quote from: Reno on March 26, 2009, 08:14:42 AM
we only need to check for equality of 10char string here

You're right.
Quote from: Dias de verano on March 26, 2009, 07:35:33 AM
I believe it's a file creation date that he wants to check, not a file name, but of which file it isn't clear.

FINFO >I want to add a line into the batch file to test if the date of the file is today. If not then stop processing.

I can see the confusion I've created here. Sorry about that. I want to test to see the file creation date for NEWBLUES.dbf is the same as the system date; if it is then continue processing. If it is not then the NEWBLUES.DBF is from an earlier date and we don't want to process this.

Does this make more sense?

>At the end of the batch, I want to copy specified files to archive.

I meant here, to copy the files into a compressed file.

Cheers
Bernard


Discussion

No Comment Found