按时间对文件进行排序的跨平台模块。
mtsort的Python项目详细描述
mtsort
按时间对文件进行排序的跨平台模块。
从文件和文件夹获取上次修改时间, 然后将它们移到一个新目录中,在新目录中对它们进行排序 文件夹。这些文件夹名称采用“yyyy-mm-dd”格式。
用于对大型文件集合进行排序,否则 手工做太乏味了!
测试并确认在Python3.6及更高版本上工作。
安装
pip install mtsort
或者使用安装脚本:
python3 setup.py install
示例
移动文件:
>>> import mtsort
>>> mtsort.mtmove('/home/test/sourcedir', '/home/test/destdir')
结果:
before: after:
. .
|-- destdir |-- destdir
|-- sourcedir | |-- 2016-07-29
|-- file1 | | |-- file1
|-- file2 | |-- 2016-07-30
|-- file3 | | |-- file2
| |-- 2016-07-31
| |-- file3
|-- sourcedir
正在复制文件:
>>> import mtsort
>>> mtsort.mtcopy('/home/test/sourcedir', '/home/test/destdir')
结果:
before: after:
. .
|-- destdir |-- destdir
|-- sourcedir | |-- 2016-07-29
|-- file1 | | |-- file1
|-- file2 | |-- 2016-07-30
|-- file3 | | |-- file2
| |-- 2016-07-31
| |-- file3
|-- sourcedir
|-- file1
|-- file2
|-- file3
或者,您可以自己启动脚本,或者从命令行启动脚本以使用它:
来自终端:
$ mtsort
从命令或powershell:
C:\> py -m mtsort