City of Newark
asked on
Robocopy Help
Robocopy question
Currently I have a .bat file that uses robocopy to copy specific files from one folder to another. Easy and it works just fine.
Issue now is the files are coming to us in multiple folders with date and timestamp. What we need to is just copy the files within those folders to another location without copying the actual folders.
Current:
@Echo off
ROBOCOPY
D:\file1\file2\file3\
D:\destination\
*.XML
/MAXAGE:1
Again files were saved within folder "file3". However, now there are multiple folders within "file3" and we need to pull just the files from within those subfolders but all the folders have different date and timestamps
Need:
@Echo off
ROBOCOPY
D:\file1\file2\file3\Folde r_test_072 519 (where date changes everyday)
D:\destination\
*.XML
Is there anyway to do this?
Currently I have a .bat file that uses robocopy to copy specific files from one folder to another. Easy and it works just fine.
Issue now is the files are coming to us in multiple folders with date and timestamp. What we need to is just copy the files within those folders to another location without copying the actual folders.
Current:
@Echo off
ROBOCOPY
D:\file1\file2\file3\
D:\destination\
*.XML
/MAXAGE:1
Again files were saved within folder "file3". However, now there are multiple folders within "file3" and we need to pull just the files from within those subfolders but all the folders have different date and timestamps
Need:
@Echo off
ROBOCOPY
D:\file1\file2\file3\Folde
D:\destination\
*.XML
Is there anyway to do this?
ASKER
How do you copy from the subfolder (dated ones) if the date changes everyday?
How do you copy from the subfolder (dated ones) if the date changes everyday?That's what the FOR /D loop does it, gets all the subfolders under the BaseDir and copies each to the DestDir.
Or do you only want to get todays single folder?
»bp
If you just want to copy the files from the one folder that has todays date (in MMDDYY format) then this should do that. This assumes the files will look like:
D:\file1\file2\file3\07251 9
D:\file1\file2\file3\07261 9
D:\file1\file2\file3\07271 9
If there is some constant text before the date then that will need to be added...
»bp
D:\file1\file2\file3\07251
D:\file1\file2\file3\07261
D:\file1\file2\file3\07271
If there is some constant text before the date then that will need to be added...
@echo off
setlocal
REM Define folders to work with
set BaseDir=D:\file1\file2\file3
set DestDir=D:\destination
REM Get current date/time in default YYYYMMDDhhmmss format
set Today=
for /f "tokens=* skip=1" %%A in ('wmic os get LocalDateTime') do (
if not defined Today (
set Today=%%A
)
)
REM Format current date/time as MMDDYY
set Today=%Today:~4,2%%Today:~6,2%%Today:~2,2%
REM Copy the files for todays folder
if exist "%BaseDir%\%Today%\" (
robocopy "%BaseDir%\%Today%\" "%DestDir%\" *.XML /MAXAGE:1
)
»bp
@City of Newark,
Are you all set with this now, or do you need more help? If all set, could you please close it out now. If you need help with the question close process take a look at:
»bp
Are you all set with this now, or do you need more help? If all set, could you please close it out now. If you need help with the question close process take a look at:
»bp
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Open in new window
»bp