Tuesday, April 23, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 2153  / 3 Years ago, sun, july 11, 2021, 6:37:50

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.


More From » nautilus

 Answers
1

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)

[#44350] Sunday, July 11, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
egantfis

Total Points: 406
Total Questions: 108
Total Answers: 108

Location: Austria
Member since Thu, Jan 7, 2021
3 Years ago
egantfis questions
Mon, Nov 1, 21, 03:37, 3 Years ago
Fri, Mar 18, 22, 23:26, 2 Years ago
Mon, Mar 6, 23, 05:03, 1 Year ago
Sun, Oct 3, 21, 23:30, 3 Years ago
Thu, Mar 10, 22, 12:28, 2 Years ago
;