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

Discus and support Include date in file created by batch file. in Windows 10 Support to solve the problem; 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... Discussion in 'Windows 10 Support' started by tcebob, Nov 29, 2017.

  1. tcebob Win User

    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.

    :)
     
    tcebob, Nov 29, 2017
    #1
  2. lacrumb Win User

    Something is creating batch files

    Have you run Windows Defender and Malwarebytes?
     
    lacrumb, Nov 29, 2017
    #2
  3. Something is creating batch files

    Yes, that plus avast. Nothing was found except the usual cookie mess
     
    dschaareman, Nov 29, 2017
    #3
  4. Include date in file created by batch file.

    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
     
    Caledon Ken, Nov 29, 2017
    #4
  5. Strahan Win User
    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.
     
    Strahan, Nov 29, 2017
    #5
  6. tcebob Win User
    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.
     
    tcebob, Nov 29, 2017
    #6
  7. yes and the date setting takes less than 30 seconds to change.

    Good luck.
     
    Caledon Ken, Apr 5, 2018
    #7
Thema:

Include date in file created by batch file.

Loading...
  1. Include date in file created by batch file. - Similar Threads - Include date file

  2. Creating batch file on Win10

    in Windows 10 Network and Sharing
    Creating batch file on Win10: Hey, this is someone's previous answer of creating a bat file but it only works if you dont change the file name first to "*.bat" before you open the file:Open the fileClick Save AsSelect the desired locationIn the File name field, type Whatever.batIn the Type field, select...
  3. Creating batch file on Win10

    in Windows 10 Gaming
    Creating batch file on Win10: Hey, this is someone's previous answer of creating a bat file but it only works if you dont change the file name first to "*.bat" before you open the file:Open the fileClick Save AsSelect the desired locationIn the File name field, type Whatever.batIn the Type field, select...
  4. Creating batch file on Win10

    in Windows 10 Software and Apps
    Creating batch file on Win10: Hey, this is someone's previous answer of creating a bat file but it only works if you dont change the file name first to "*.bat" before you open the file:Open the fileClick Save AsSelect the desired locationIn the File name field, type Whatever.batIn the Type field, select...
  5. Creating a Batch File Example

    in Windows 10 Support
    Creating a Batch File Example: Hey All, I am not looking for someone to do the work for me, I'm trying to get a general idea of what I need to start at. It's been a few years since I've done a batch file and Windows 10 is so different than Windows 7. I am essentially wanting a batch file, that if I type a...
  6. Need help to create a batch file

    in Windows 10 Support
    Need help to create a batch file: Hi Folks, I need to create a batch file that automatically takes permissions & delete the following file & folders File:- C:\Windows\System32\SecurityHealthSystray.exe Folders:-...
  7. Batch file to include all subdirectories. Help

    in Windows 10 Support
    Batch file to include all subdirectories. Help: Trying to get batch file to include all subdirectories. echo **Have double apostrophe (" ") for file path that includes spaces** echo. echo. SET /p B=Enter the folder location (Then press ENTER): rem cd "%B%" pause for %%v in (%B%*.afd) DO ( cmd /C ""C:\Program...
  8. Create batch files with Batch?

    in Windows 10 Software and Apps
    Create batch files with Batch?: How to create Batch and VBS files with Batch? So I write a batch file which I then convert to exe that creates new folders in a certain directory and then creates batch and VBS files with a certain content and saves them in the created folder. So it's similar to a program...
  9. Batch file to current date and time

    in Windows 10 Customization
    Batch file to current date and time: Dear expert. Can you help me to batch file to change system date and time to current? Best regards, https://answers.microsoft.com/en-us/windows/forum/all/batch-file-to-current-date-and-time/2c75b187-3561-4604-b9b5-218db993a6f6
  10. Create Multipurpose batch file

    in Windows 10 Software and Apps
    Create Multipurpose batch file: Hope this is the correct sub forum for this.. Often use a variety of command line functions e.g. winver / netplwiz etc etc Is there a way of creating a batchfile to include multiple commands with a number option to select...would be so handy i.e. 1 Netplwiz 2 Winver...