Ren*_*V R 2 time files filename date
我想使用键盘快捷键使用当前日期和时间保存文件名,这可能吗?
例子:
array_12:35:16 28-05-16.php
somename_currentdatetime.php
Run Code Online (Sandbox Code Playgroud)
下面的脚本将允许您右键单击文件并timestamp从scripts菜单中选择选项。
右键单击 -> 脚本 -> 时间戳
该文件是定时的
timestamp
(无扩展名) ìn ~/.local/share/nautilus/scripts
。如果目录尚不存在,则创建该目录。如果扩展名在文件上,脚本会在名称的“正文”和扩展名(任何)之间插入时间/日期。如果没有,它将在名称后添加时间/日期。
#!/usr/bin/env python3
import os
import shutil
import time
current = os.getenv(
"NAUTILUS_SCRIPT_SELECTED_FILE_PATHS"
).replace("file://", "").replace("%20", " ").strip()
t = time.strftime("%H:%M:%S_%d-%m-%Y")
name = current.split("/")[-1]; path = current[:current.rfind("/")]
splitmark = name.rfind(".")
newname = name[:splitmark]+"_"+t+name[splitmark:] if splitmark != -1 else\
name+"_"+t
newfile = os.path.join(path, newname)
shutil.move(current, newfile)
Run Code Online (Sandbox Code Playgroud)
该脚本使用的python
'sshutil.move()
对目录和文件同样有效。