Copy and Move with auto date/timestamp

Oct 18, 2009
Copy and Move /TS (or similar) automatically adds a datestamp or date+timestamp to the target filename, e.g.

Copy /TS=D MyFile.txt

The copy is MyFile-2020-09-18.txt

Move /TS=DT MyFile.txt NewLoc.txt

The moved file is NewLoc-2020-09-18-12-23.txt

Maybe NewLoc_2020 etc instead, probably allow using one of TCC's standard format indicators.
Apr 2, 2011
North Carolina, USA
Could use TCC's build in Date / time routines to retrieve the current date and time....
I wrote this a few weeks back to do something similar. I had a need to rename a bunch of JPG and GIF files I had, to include the creation date (not time) in the filename for a downstream image processor.

The usage would be "renimage *.jpg JOB1", and would rename X.JPG to be JOB1_2020_09_18_01.jpg and Y.JPG to be JOB1_2020_09_18_02.jpg, for example. If you extract the file time as well as the date, and change the rename operation to a copy, it does pretty much what the requested /TS operation above does.

@echo off
::    Rename image files to include creation date and time.
:: Author:        William de Haan
:: Creation date: Sun, 14 Jun 2020 at  8:16pm
:: Last Revision: Sun, 14 Jun 2020 at 10:00pm
:: Usage:
set BATCHFILE=%TEMP%\batchfile.btm
del /qe %BATCHFILE%
echo echo Executing %BATCHFILE% >> %BATCHFILE%

iff [%1] == [] then
   echo usage: %0 name [filespec]

set NAME=%1
iff [%FILESPEC%] == [] then
   set FILESPEC=*.jpg *.jpeg *.gif *.png

:: Iterate through files by date, processing each date independently
set OLDDATE=1980-01-01
for /o:d f in (%FILESPEC%) do (
   set FD=%@filedate[%F%,w,4]
   iff not [%FD%] == [%OLDDATE%] then
      set OLDDATE=%FD%
      gosub PROCESSDATE %FD%


   set DATECOUNT=0
   for /[d%FD%,%FD%] f in (%FILESPEC%) do (
      set DATECOUNT=%@inc[%DATECOUNT%]

   echo Processing date %FD%, count: %DATECOUNT%

   set DIGITS=2
   if %DATECOUNT% GT 99  set DIGITS=3
   if %DATECOUNT% GT 999 set DIGITS=4

   set COUNT=0
   for /[d%FD%,%FD%] f in (%FILESPEC%) do (
      set COUNT=%@inc[%COUNT%]

      :: Write to a batch file rather than renaming the file directly. If
      :: the file is renamed here, then the newly renamed file appears in
      :: the for loop, and it will be processed again, infinitely.
      set FD1=%@replace[-,_,%@filedate[%F%,w,4]]
      iff isfile "%@unquote[%F%]" then
         iff not isfile "%@unquote[%NAME%]_%FD1%_%COUNT%.*" then
            echo ren /qe "%@unquote[%F%]" "%@unquote[%NAME%]_%FD1%_%COUNT%.*" >> %BATCHFILE%

:SETDIGIT [count digits]
   set TMP1=000%%COUNT%
   set TMP2=%@right[%DIGITS%,%TMP1%]
   set COUNT=%TMP2
Oct 18, 2009
I realize these can be done with custom coding, but my suggestion is for an addition, and with fairly simple syntax.

I do have some routines that add a date and timestamp for a specific Excel *.xlam file. But that has to get the full path, parse the extension, construct the addition, create the new target path, and then do the copy under the new target filename.

When I started writing the suggestion I just thought, "Okay, copy and add -CCYYMMDD".

Then I thought, "What if they want to move instead of copy?" Then, "Wait, people might need the time too." Then, "They might only want the time." Then, "They probably would want to specify the format--and TCC already supports multiple formats."
Similar threads
Thread starter Title Forum Replies Date
C Declined Add switch to MOVE to not make empty destination folders. (COPY's /F) Suggestions 4
C Move/Copy switch not make empty destination sub-folders Suggestions 6
rconn New parameter /WTF - COPY/MOVE - Wait on disk full (rather than halt with error) Suggestions 1
S Done COPY and MOVE Suggestions 0
S Declined Enhanced @FILE for COPY, DESCRIBE, MOVE, RENAME, SYNC, TOUCH /R Suggestions 0
D Done Suggestion for commands to move/copy a folder Suggestions 7
samintz Done Support ~ and :path in COPY Suggestions 5
Alpengreis Done Preserves directory attributes for COPYDIR & COPY Suggestions 3
D Duplicate directory path and copy files and subdirectories. Suggestions 4
C Feature Request: Gain some elements of the XXCOPY feature set in COPY or a new "Mass-Copy" command Suggestions 0
R Declined wish-list: add a command to copy a file to clipboard. Suggestions 17
D Done Suggestion: keystroke to copy previous argument Suggestions 3
R Done IDE copy (OR REMOVE) Set var name to Watch list by hotkey Suggestions 2
Alpengreis Done Add "Slow copy" (/WAIT) parameter to SYNC command Suggestions 1
C Declined copy /w suggestion Suggestions 2
WinLanEm Done COPY modify Suggestions 4
rconn Done Copy with Backup Versions Suggestions 0
Roedy Declined Copy to DVD Suggestions 2
wbiebel Done copy /u /s Suggestions 1
nickles Make move rename conflicting files Suggestions 0
fpefpe Done move like unix mv Suggestions 11
S Done MOVE /k Suggestions 4
E Done move @unquote, @unquotes in help docs Suggestions 0
Joe Caverly Done Auto-Attach Consoles and Desktops Suggestions 0
S Add support for Git auto-completion Suggestions 0
rps Declined Add auto-load directives to tcmd.ini Suggestions 3
vefatica Done Auto-load .watch files Suggestions 1
T Done TCMD tabbed toolbar - auto-save changes Suggestions 0

Similar threads