Consulting

Results 1 to 3 of 3

Thread: DOS Batch Copy question

  1. #1

    DOS Batch Copy question

    I have the need to create a quick batch file (DOS) that copies a file to a new directory. However, I need to "Add the date" to the filename when it is copied.

    For example:
    filename = TestFile.pdf
    new filename = 1-19-12TestFile.pdf

    The date needs to be the current system date. I know that %date% will give me the system date.

    How do you combine the date and the filename.

    Appreciate the help.
    ttfn

    Kicker

  2. #2
    Assuming echo %date% returns dd/mm/yyyy (swap the Day and Month variables if not), try something like this.

    SET Today=%Date: =0%
    SET Day=%Today:~-10,2%
    SET Month=%Today:~-7,2%
    SET Year=%Today:~-4%
    COPY file.txt %Day%-%Month%-%Year%file.txt

    See http://www.robvanderwoude.com/datetimentparse.php

  3. #3
    Thank you. It has been many (way to many) years since I used DOS and batch files.

    Appreciate the response.
    ttfn

    Kicker

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •