Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Xcopy with dynamic file name as parameter  (Read 4542 times)

0 Members and 1 Guest are viewing this topic.

Osoful

    Topic Starter


    Newbie

    • Experience: Beginner
    • OS: Unknown
    Xcopy with dynamic file name as parameter
    « on: August 20, 2012, 08:55:35 PM »
    I need to copy a file from one directory to another directory using xcopy. The file that I need to copy is always named differently based on the date it was created.
    My questions are: 
    a)how can I construct the file name dynamically, e.g. 2012-08-08-tfile.txt
    and 
    b) can I pass this file name to xcopy 

    Thanks for your help.

    foxidrive



      Specialist
    • Thanked: 268
    • Experience: Experienced
    • OS: Windows 8
    Re: Xcopy with dynamic file name as parameter
    « Reply #1 on: August 20, 2012, 09:12:31 PM »
    Does the file always have tfile in the name?

    Is the file the only .txt file in the folder?


    Osoful

      Topic Starter


      Newbie

      • Experience: Beginner
      • OS: Unknown
      Re: Xcopy with dynamic file name as parameter
      « Reply #2 on: August 20, 2012, 10:02:07 PM »
      yes, it's always tfile at the end. it's currently not the only file in the directory but I could set it up that way if it makes it easier.

      foxidrive



        Specialist
      • Thanked: 268
      • Experience: Experienced
      • OS: Windows 8
      Re: Xcopy with dynamic file name as parameter
      « Reply #3 on: August 21, 2012, 03:20:34 AM »
      Then this should work from the same folder.

      Code: [Select]
      @echo off
      for %%a in (*tfile.txt) do xcopy "%%a" "d:\target\"