Windows 10: Include date in file created by batch file.

  1. tcebob's Avatar
    Posts : 390
    Windows 10 pro 1803/17134.285
       29 Nov 2017 #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 ComputerSystem Spec

  2. Caledon Ken's Avatar
    Posts : 10,553
    Windows 10 Pro x64 Build 1803
       29 Nov 2017 #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

    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.

      My ComputerSystem Spec

  3.    29 Nov 2017 #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 ComputersSystem Spec

  4. tcebob's Avatar
    Posts : 390
    Windows 10 pro 1803/17134.285
    Thread Starter
       30 Nov 2017 #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 ComputerSystem Spec

  5. Caledon Ken's Avatar
    Posts : 10,553
    Windows 10 Pro x64 Build 1803
       30 Nov 2017 #5

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

    Good luck.
      My ComputerSystem Spec


Related Threads
Running Windows 10 fully updated. My File Explorer windows show several columns in the Details View: the Filename, Date Modified, Date Created, etc. The Date is formatted like this: Day Month Date Time with the Day and Month truncated to 3 letters...
hi, i want to disable the change time and date in windows ten using batch file, i am using this script to show and hide hidden file @echo off REG ADD "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /V Hidden /T REG_DWORD /D...
How to show each time in File explorer the date created. Under the seach box, you can right to choose wish column you want to show. I often choose to add date created. But each time I have to go right click it, and choose it over and over. Is it not...
The column heading in Win 10 File Explorer is 'Date'. But which one? I've always been used in XP to the default being 'Date modified', but it seems that here it's Date created? Several re-saves have left 'Date' unchanged. 112393 -- Terry,...
Hi there forum, how do you change the Visual effects using a batch file or registry file. Thanks, Edward.
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 16:35.
Find Us