python文件整理工具

来源:互联网 发布:淘宝助理有客服吗 编辑:程序博客网 时间:2024/05/10 09:04

做项目的时候,为了方便,总是直接把文件放在桌面上。时间一长,桌面上的文件堆积如山。到了必须清理的时候,整理比较耗费时间。直接删除又不太放心,因为有些文件可能还会用到。

通常我的做法是,新建一个文件夹,把文件全部移动到里面,为桌面腾出空间,然后有空的时候再回来整理。

因为我经常这么做,重复劳动。重复劳动都应该让程序代劳。所以我用python写了一段脚本,实现了这个简单的功能。以下是源码:

#This Python file uses the following encoding: utf-8import osimport shutilfrom datetime import datetimecurDir = os.curdir# create the folder to store the files in current directorydstFolder  = os.path.join(curDir, datetime.now().strftime('%m-%d %H-%M'))if not os.path.exists(dstFolder):    os.makedirs(dstFolder)# list and move the file in current directory to the folder just createdfiles = os.listdir(curDir)for f in files:    if os.path.isfile(f) and f != 'CleanDirectory.exe':        srcPath = os.path.join(curDir, f)        dstPath = os.path.join(dstFolder, f)        shutil.move(srcPath, dstPath)

我把它做成exe了,可以在这里下载。

使用说明:

把exe放在某个目录下,双击运行。当前目录下的文件(不包括文件夹)就会被移动到一个文件夹下(新文件夹以当前时间命名)。

我写它主要目的是为了清理桌面,放到桌面,运行一下,桌面上的的文件就移走,说法清爽。

注意!

不要修改exe的名称,修改的话也能用,只是exe也会被移动到新建的文件夹中。

0 0