Batch file for one current date in text file

April 2018


I need a batch file to get the current date and time of my computer and put it in a text file every time I run it. But I need the most current date&time to replace the previous within the same text file, so that my file can have only one record, even if I run it multiple times.

I found this code:

<codeecho %date% %time% >> log.txt></code>

But this one just adds the next date under the previous one.


You can use the gettime() function in bierscripting to get the current date and time and rename files using that. For example, the following script will rename all files in folder "C:/folder" by appending a timestamp to file names.

# Script AppendTimestamp.txt
var str folder, list, file, extn, name
lf -n "*" $folder ($ftype=="f") > $list
while ($list <> "")
    lex "1" $list > $file ; stex -p "^/^l[" $file > $name ; stex "[^.^l" $name > $extn
    system rename ("\""+$file+"\"") ("\""+$name+"_"+gettime()+$extn+"\"")

To run the script, copy and paste the script into file C:/Scripts/AppendTimestamp.txt, then enter the following command in biterscripting

script "C:/Scripts/AppendTimestamp.txt" folder("C:/somefolder")

It will rename all files in folder "C:/somefolder" accordingly.


Thanks to Richard.Williams for this tip on the forum.
Published by aakai1056. Latest update on January 22, 2010 at 07:56 AM by aakai1056.
This document, titled "Batch file for one current date in text file," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (
Recycle Bin – Deleted items are permanently removed automaticall
Creating a Batch File to copy a directory