Windows Server: Copy today's file using batch file?
-
hi all i am having 'n' number of file, i want to copy only todays file based on date modification.
-
Answer:
SET CurrentDate=%date:~-7,2%-%date:~-10,2%-%date:~-4,4% xcopy C:\folder\*.* C:\otherfolder\*.* /d:%CurrentDate% Try the above in a batch file replacing C:\folder and C:\otherfolder\ with your source and destination folders. xcopy allows the /D switch which copies files changed on or after the specified date. eg. xcopy source destination /D:m-d-y Specifying the date your self would work and you need run the command xcopy source destination /D:08-09-2013 for files dates September 8th. But for a more automated method a little date manipulation is required. The problem with xcopy /D on its own is the date format accepted for the /D switch is m-d-y and windows displays the date as mm/dd/yyyy. The first line is therefore manipulating the date into the required order with dashes instead of slashes and setting it into the variable CurrentDate, which is what were then providing into the /D switch.
Farooq Rauf at Quora Visit the source
Other answers
PowerShell makes it easier. You can define today at "since 00;00 midnight" or "within the last 24 hours." # start at midnight [datetime]$today = Get-Date -f 'MM/dd/yyyy' # or last 24 hours [datetime]$today = ( Get-Date ) - ( New-TimeSpan -day 1 ) Get-ChildItem -Path | Where-Object { $_.LastWriteTime -gt $today } | Copy-Item -Destination $dest
Tim Dunn
Related Q & A:
- how delete node in xml file using php?Best solution by Stack Overflow
- How to skip the input in batch file?Best solution by Stack Overflow
- How to run an interactive batch file on windows from a service?Best solution by Stack Overflow
- How to get the file using it's URL in Javascript?Best solution by befused.com
- How to make a batch file copy itself?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.