Can anyone suggest a script that will rename a file with the
existing filename appended with date stamp? Something that
can be used in a .bat file?

Recommended Answers

All 2 Replies

Python or vbScript? This is the Python version

import os
import sys
import glob
import shutil
import datetime

for arg in sys.argv[1:]:
    for file in glob.glob(arg.replace("[", "[[]")):
        base,extn = os.path.splitext(file)
        newname = base + ' ' + str(datetime.date.today()) + extn
        if not os.path.exists(newname):
            shutil.move(file,newname)

Save it in a file like appenddate.py and run it by

appenddate file [file...]

where file is a file name or pattern (Windows wildcards * and ?) as in

appenddate *.jpg *.txt

That weird replace in the glob line is to account for [ and ] being valid Windows characters in file names but something else in a glob call.

You're welcome.

commented: excellent +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.