1: The following code creates a date stamped destination folder correctly, ie:
MyServerMyFilesVersionYYYMMDDHHNN
2: However, only files from the source are copied over, not the folder. What I get is:
MyServerMyFilesVersionYYYMMDDHHNNMyfile01.txt
MyServerMyFilesVersionYYYMMDDHHNNMyfile02.txt
What I want to achieve is:
MyServerMyFilesVersionYYYMMDDHHNNMyFolderToCopyMyfile01.txt
MyServerMyFilesVersionYYYMMDDHHNNMyFolderToCopyMyfile02.txt
What am I doing wrong?
Note: I cannot specify the SOURCE as C:Users123456 as there may be other folders in this path that I do not wish to copy.
Thanks in advance for any help!
SET SOURCE=”C:Users123456MyFolderToCopy”
SET DESTINATION=”MyServerMyFilesVersion”
REM – CREATE DATE STAMP FOR FOLDER:
for /f “delims=” %%a in (‘wmic OS Get localdatetime ^| find “.”‘) do set dt=%%a
SET YYYY=%dt:~0,4%
SET MM=%dt:~4,2%
SET DD=%dt:~6,2%
SET HH=%dt:~8,2%
SET Min=%dt:~10,2%
SET STAMP=%YYYY%%MM%%DD%%HH%%Min%
SET NEW_FOLDER=%DESTINATION%%STAMP%
MKDIR %NEW_FOLDER%
XCOPY %SOURCE% %NEW_FOLDER% /E