KRS12
asked on
Copy files by current date only
I need to copy files from the source to destination and only copy the files with the current date : I can create copy etc, but it is grabbing all the files not just the current date. I don't know what I am missing.
@ECHO Collect Todays WSA Logs.......
Pause
For /f "tokens=1-3 delims=/ " %%a in ('date /t') do (set currentDate=%%a-%%b-%%c)
For /f "tokens=1-3 delims=/: " %%a in ('time /t') do (set currentTime=%%a%%b%%c)
echo %currentDate%-%currentTime %
set todaysLogs=%currentDate%-- %currentTi me%
mkdir d:\Logs\%todaysLogs%\WSA
REM WSA
xcopy /i /e "\\SOURCE\c$\WINDOWS\temp\ *.TMP" "D:\Logs\%todaysLogs%\WSA" %date:~4,2%-%date:~7,2%-
%date:~4%
@ECHO Collect Todays WSA Logs.......
Pause
For /f "tokens=1-3 delims=/ " %%a in ('date /t') do (set currentDate=%%a-%%b-%%c)
For /f "tokens=1-3 delims=/: " %%a in ('time /t') do (set currentTime=%%a%%b%%c)
echo %currentDate%-%currentTime
set todaysLogs=%currentDate%--
mkdir d:\Logs\%todaysLogs%\WSA
REM WSA
xcopy /i /e "\\SOURCE\c$\WINDOWS\temp\
%date:~4%
ASKER
When I ran the batch file it returned an invalid parameter: /d:/2-17-05/0 See below:
xcopy /i /e /d:/2-17-05/0 \\SOURCE\c$\WINDOWS\temp\* .TMP" "D:\Logs\%todaysLogs%\WSA" \05-07-201 7--1027AM\ WSA
Invalid parameter - /d:/2-17-05/0
xcopy /i /e /d:/2-17-05/0 \\SOURCE\c$\WINDOWS\temp\*
Invalid parameter - /d:/2-17-05/0
I think your xcopy line should be:
xcopy /i /e "\\SOURCE\c$\WINDOWS\temp\*.TMP" "D:\Logs\%todaysLogs%\WSA\%currentDate%-%currentTime%\"
Please change the %date:~5,2%-%date:~8,2%-%d ate:~0,4% at your OS.
The different OS have different date time formatting.
the xcopy /d parameter need m-d-y date as input.
Please run
xcopy /?
see more information
The different OS have different date time formatting.
the xcopy /d parameter need m-d-y date as input.
Please run
xcopy /?
see more information
ASKER
xcopy /i /e /d:%date:~5,2%-%date:~8,2% -%date:~0, 4% "\\SOURCE\c$\WINDOWS\temp\ *.TMP" "D:\Logs\%todaysLogs%\WSA"
Returned another error: Invalid switch - /2-17-06/0
Our date format is dd/mm/yyyy : 06/07/2017
Returned another error: Invalid switch - /2-17-06/0
Our date format is dd/mm/yyyy : 06/07/2017
The %date:~m,n% it return the part of index positon value, for example
%date:~5,2% it return the current date string from 5th char and return 2 chars.
You should change the %date:~5,2%-%date:~8,2%-%d ate:~0,4%
to
%date:~4,2%-%date:~0,2%-%d ate:~7,4%
%date:~5,2% it return the current date string from 5th char and return 2 chars.
You should change the %date:~5,2%-%date:~8,2%-%d
to
%date:~4,2%-%date:~0,2%-%d
ASKER
Same error. the only thing that works is the d:/07/07/2017 but I have to modify the script each day to collect what I need.
You may be able to use part of a powershell script that I got help with here by changing the code line using wildcards. See here:
https://www.experts-exchange.com/questions/29019605/Need-new-Windows-PowerShell-script.html
https://www.experts-exchange.com/questions/29019605/Need-new-Windows-PowerShell-script.html
You needn't modify the script every day.
I found why the command don't work for you now:
I'm using the date format at my system: yyyy-mm-dd.
The seperator at my system is "-", but at your system, the seperator is "/", Please understand my command and change it as your system.
such as(you'd better use echo command test the output first):
%date:~4,2%/%date:~0,2%/%d ate:~7,4%
Test the output:
echo %date:~4,2%/%date:~0,2%/%d ate:~7,4%
Once you get correct date value, then you can put the %...% to that xcopy command.
I found why the command don't work for you now:
I'm using the date format at my system: yyyy-mm-dd.
The seperator at my system is "-", but at your system, the seperator is "/", Please understand my command and change it as your system.
such as(you'd better use echo command test the output first):
%date:~4,2%/%date:~0,2%/%d
Test the output:
echo %date:~4,2%/%date:~0,2%/%d
Once you get correct date value, then you can put the %...% to that xcopy command.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This solution worked perfectly thank you
xcopy /i /e /d:%date:~5,2%-%date:~8,2%