Batch file for one current date in text file

July 2017




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


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 (ccm.net).