0

I'm using Xcopy to copy a folder across a network

XCOPY "C:\Documents and Settings\Administrator\Desktop\File\Output*." "C:\new" /s /e /c

I want the folder at the destination to be named with the date. E.G .\19-10-2013 How do i go about that?

1 Answer 1

1

You could do it like this:

XCOPY "C:\Documents and Settings\Administrator\Desktop\File\Output*." "C:\new\%date%\" /s /e /c

This will create a directory with the format of your date. But when sorting the directories by name they will not be sorted by date. I would transform 19-06-2013 to 2013-06-19.

If you want a directory like YYYY-MM-DD you could do it like this:

@echo off
for /F "usebackq tokens=1,2,3 delims=-" %%I IN (`echo %date%`) do set mydate=%%K-%%J-%%I
XCOPY "C:\Documents and Settings\Administrator\Desktop\File\Output*." "C:\new\%mydate%\" /s /e /c
pause

If your date format (and separator) is different you need to fiddle a bit to get it right.
(if you need help with that let us know your date format.)

2
  • Thanks man. I've used the first one sucessfully. i'm actually creating a job in MSSQL 03 that will run that. it's working via command prompt but timing out as a job. i'll troubleshoot that though.
    – Zigmaphi
    Oct 7, 2013 at 19:33
  • Reading this article may help with the renaming of destination "File Names" rather "Folder Names" if you want: stackoverflow.com/a/50255574/1830909
    – QMaster
    May 10, 2018 at 11:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .