在工作中,经常会有一些文件逐渐侵占我的桌面,时间久了,很难在桌面快速找到需要的
文件,定期清理是个不错的办法,但总感觉不够丝滑,而且文件应该删除还是保留,又应
该存到哪里,一直以来,给选择困难症的我造成了很大的困扰,
直到,看到了这个帖子
作者的想法很好,我在其基础上做了增强,写出了下面的脚本:
archive.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| import os import sys import shutil import time import readline import rlcompleter
root_dir = os.getcwd() time_str = time.strftime("%y%m%d", time.localtime())
def completer(text, state): options = [] for option in os.listdir(root_dir): if option.startswith(time_str + '-' + text): options.append(option.strip(time_str + '-')) if len(options) == 0: options.append('Default') if state < len(options): return options[state] else: return None
readline.parse_and_bind('tab: complete') readline.set_completer(completer)
archive_name = input('归档为:')
if archive_name == '': archive_name = 'Default'
dest_dir = os.path.join(root_dir, time_str + '-' + archive_name)
if not os.path.exists(dest_dir): os.makedirs(dest_dir)
for f in sys.argv[1:]: shutil.move(f, dest_dir)
|
环境准备
- 安装 Python;
- 安装 readline,Windows 下命令为
pip install pyreadline
使用方法
- 在你喜欢的归档目录下建立 archive.py 文件,填入上面的脚本内容;
Win + R
输入 shell:sendto
回车;
- 在此目录下新建快捷方式链接到之前建的 archive.py 文件,快捷方式名称可以按自己
喜好定制,我命名为了”今日归档”;
- 此时,右键发送到菜单就有了发送到 -> 今日归档;
- 在某个文件上右键->发送到->今日归档,在弹出的输入框中填入你喜欢的名称,不输入
则归档到 Default;