Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Is there a simple way (maybe a script), to automatically insert the current date into the filename of a newly created document either in nautilus or in Libreoffice?

A function like that would be useful for me, since I produce a lot of documents and sort them by making their names start with the date of their creation.

share|improve this question

3 Answers 3

up vote 1 down vote accepted

Put this code into a file (e.g. add_date) move it to the ~/.gnome2/nautilus-script directory. Perhaps you need to add execute permissin (chmod a+x add_date). If you rightclick on a file in nautilus, you can append the date before the file name like in How can I write nautilus scripts in Python. The format can be changed in the row beginning with prefix = (strftime formatting)

#!/usr/bin/env python
# coding: utf-8

import sys
import os
import datetime
import shutil

datetime = datetime.datetime.now()
prefix = datetime.strftime('%y_%m_%d_%H-%M_')

if len(sys.argv) == 1:
    command = os.path.split(sys.argv[0])[-1]
    print("usage: {0} file...".format(command))

else:
    for _file in sys.argv[1:]:
        newfile = prefix+_file
        print("New file: {0}".format(newfile))
        shutil.move(_file, newfile)
share|improve this answer
    
Thank you, works like a charm! Great job! –  YSN Jul 6 '11 at 1:02

Nautilus-actions or Nautilus scripts may help. You could get something like a "timestamp" command in the contextual menu. Nautilus-actions lets you choose which file types will have the command available.

Nautilus-actions is available in software-center and then in settings menu. Nautilus scripts are those stored in "~/.gnome2/nautilus-script"

Doing so, your files won't be automatically timestamped, but the job will be easier.

share|improve this answer

Unfortunately, no. You can however rename the files using a batch renaming program (those are numerous in the Software Centre).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.