Include date in file created by batch file.


  1. Posts : 481
    Windows 10 pro 1903 1862.145
       #1

    Include date in file created by batch file.


    How can I add to this batch command to include the date:

    xcopy C:\all\* Z:\Allbak\* /E /Y /C

    I'd like the resulting file to be named "Z:\Allbak171129" (yr mo day).

    The plan is to set up a task schedule to run the batch file every week. I want to keep several previous backups just in case.
      My Computer


  2. Posts : 30,178
    Windows 11 Pro x64 Version 23H2
       #2

    Hi tcebob.

    If you change the format of your "Short Date" to yyyy-mm-dd (Start, Settings, Time and Language, bottom right hand side, "Change Date and Time formats") then I think this will work. You used the word file but it appears you want folder name to have date. The /Y command suppress error messages on overwrites, would there be any if folder is new for each run.

    xcopy C:\all\* Z:\Allbak%date%\* /E /Y /C

    I won't claim to be an xcopy expert but are you trying to copy your entire c: drive to a folder on Z:?

    I think it would be

    xcopy c: z:\Allbak%date% /s /h /e /c

    referencing this doc

    https://technet.microsoft.com/en-ca/...or=-2147217396

    Of course I could be wrong and I did not test.

    Depending on how much data and software you have this could be a very lengthy process. Have you looked at File History and or the use of Macrium Reflect. Some discussion about File History and if it will be replaced in some future Feature Update.


    Ken
      My Computer


  3. Posts : 34
    Windows 10
       #3

    Rather than fiddle with the Windows format settings, you'd be better off just building a date code from the current %date% results. Changing the Windows setting is a large, full range change. For example, if I echo %date% I get:

    Wed 11/29/2017

    So to make a date code, I'd just do set datecode=%date:~4,2%%date:~7,2%%date:~10,4%. Then doing echo %datecode% gives me 11292017.
      My Computers


  4. Posts : 481
    Windows 10 pro 1903 1862.145
    Thread Starter
       #4

    Thanks both!

    C:\all is a subdirectory in which I keep all personal data, such as \toolbars, \pictures, \documents, etc.

    The reason for the format "Z:\Allbak171129" is several of them will sort automatically by date under "name."
    I wasn't aware of the variable %date%. Good to know.
      My Computer


  5. Posts : 30,178
    Windows 11 Pro x64 Version 23H2
       #5

    yes and the date setting takes less than 30 seconds to change.

    Good luck.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 18:18.
Find Us




Windows 10 Forums