1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Touch command — I Need to touch matching files in another directory.

Discussion in 'Support' started by cwc, Sep 24, 2015.

  1. cwc

    cwc

    Joined:
    Mar 9, 2010
    Messages:
    11
    Likes Received:
    0
    I’ve used the Touch command to copy the dates & times from one file to another, but now I have thousands of files to deal with. I need to copy the dates and times of a directory and its files and subdirectories to matching files and subdirectories in another directory. After studying the documentation on the Touch command, I tried the following —
    touch /r "E:MyDir\" /s "F:MyDir\"

    It didn’t work — I got a “Can’t find the file "F:MyDir\" message.

    Can the Touch command do what I need it to do? If so, what syntax should I use?

    Thanks.

    BTW, I’m using TC 18.00.16 x64.
     
  2. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,287
    Likes Received:
    39
    You have the same files and directory structure under E:\MyDir and F:\MyDir? Sounds to me like a job for FOR /D.
     
  3. Christian Albaret

    Joined:
    Jul 1, 2008
    Messages:
    154
    Likes Received:
    1
    You are trying to use TOUCH with a file selection similar to what COPY does: with both source and target being directories, COPY takes all files in the source, determines the corresponding file in the target, and performs the copy.

    I am afraid with TOUCH you can only:
    - TOUCH with the date of a single file:
    Code:
    TOUCH /r "E:\MyDir\RefFile" /s "F:\MyDir"
    
    - write a loop
    Code:
    FOR /R %s "E:\MyDir\*" TOUCH /R %s %@REPLACE["E:\MyDir\","F:\MyDir\",%s]
    
    You get the "Can't find the file …" message because TOUCH rejects directories unless you include them through a /A:D option.
     
  4. cwc

    cwc

    Joined:
    Mar 9, 2010
    Messages:
    11
    Likes Received:
    0
    The FOR command as shown above didn’t work — I got an error message, «Can’t find "E:\MyDir\*"» —
    but thanks anyway!

     
  5. cwc

    cwc

    Joined:
    Mar 9, 2010
    Messages:
    11
    Likes Received:
    0
    Thanks, everybody! I found another way to get my problem solved.
     
  6. Charles G

    Joined:
    Apr 2, 2011
    Messages:
    1,015
    Likes Received:
    0
    @cwc might be nice and helpful to others to post your solution....
     

Share This Page