Batch file for one current date in text file

December 2016




Issue


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.

Solution


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 <> "")
do
    lex "1" $list > $file ; stex -p "^/^l[" $file > $name ; stex "[^.^l" $name > $extn
    system rename ("\""+$file+"\"") ("\""+$name+"_"+gettime()+$extn+"\"")
done




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.

Note


Thanks to Richard.Williams for this tip on the forum.

Related :

This document entitled « Batch file for one current date in text file » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.