Solved Help creating a program to copy data from last 24 hours

January 23, 2015 at 21:39:49
Specs: Windows XP
Hi all, newbie here, I need help to create a batch file that will copy data (log files) from one folder to another from the last 24 hours to the current time the batch file was run/open.

Previously, I have used this code and it worked, however this code is deficient as it only copy the log files based on the current date.
Lets say if somebody is seeking for data from the last 24 hours, and he/she runs the program on 24 Jan, 12.01 am, thus all the data from the previous day wont be copied.

Below is the code I have used previously.

for /F "tokens=1* delims= " %%A in ('DATE/T') do set SYSDATE=%%B
set DATE_YYYY=%SYSDATE:~6,4%
set DATE_MM=%SYSDATE:~3,2%
set DATE_DD=%SYSDATE:~0,2%
set DATE_MM_DD_YYYY=%DATE_MM%-%DATE_DD%-%DATE_YYYY%
echo %DATE_MM_DD_YYYY%
xcopy "w:\documents\*.doc" c:\dest /E /Y /D:%DATE_MM_DD_YYYY%


See More: Help creating a program to copy data from last 24 hours

Report •


✔ Best Answer
January 27, 2015 at 18:49:35
Well, to answer question #1: run the script. It shows the final result. After reviewing xcopy, I figure you probly need to replace / with - in the output date:
set last=%last:/=-%
:: then just:
:: debugging left in place, remove for active-duty
echo xcopy "w:\documents\*.doc" c:\dest /E /Y /D:%last%
pause
:: end debugging
xcopy "w:\documents\*.doc" c:\dest /E /Y /D:%last%

Then put your xcopy right after that, as listed above.



#1
January 26, 2015 at 07:14:38
any help guys, really need some if possible?

Report •

#2
January 26, 2015 at 19:20:49
I avoid date-math in batch. Although it is feasible, it is cumbersome and subject to error. This approache uses vbscript to do the heavy lifting:
::---------- begin batchscript
@echo off & setlocal enabledelayedexpansion
if "%1" neq "" (
set x=%1
) else (
:: this assumes format 3-letter DOFW precedes standard date
set x=%date:~4%
)
>e.vbs echo wscript.echo dateadd("h",-24,wscript.arguments(0))
for /f "tokens=*" %%a in ('cscript e.vbs %x%') do set last=%%a
echo %last%
::====== end
as you will note, this script allows override of default current-date (mostly for testing).

Report •

#3
January 26, 2015 at 20:11:54
I see, does this script work? Where should xcopy be put?

Report •

Related Solutions

#4
January 27, 2015 at 18:49:35
✔ Best Answer
Well, to answer question #1: run the script. It shows the final result. After reviewing xcopy, I figure you probly need to replace / with - in the output date:
set last=%last:/=-%
:: then just:
:: debugging left in place, remove for active-duty
echo xcopy "w:\documents\*.doc" c:\dest /E /Y /D:%last%
pause
:: end debugging
xcopy "w:\documents\*.doc" c:\dest /E /Y /D:%last%

Then put your xcopy right after that, as listed above.


Report •

Ask Question