• 技术文章 >Python技术 >Python基础教程

    python电脑桌面中整理exe程序

    小妮浅浅小妮浅浅2021-10-27 09:44:34原创4391

    1、引入库os,time,shutil。

    2、创建分类字典。

    3、传入桌面路径。

    将桌面路径以字符串形式赋值给path,并将桌面所有文件名存入dirs。

    4、在指定路径创建文件夹用以保存分类文件。

    5、判断文件并进行移动分类。

    6、程序打包为exe。

    实例

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    import os,time,shutil

    formats = {

     "音频":[".mp3",".wav"],

     "视频":[".mp4",".avi",".mov",".wmv",".asf",".rm",".rmvb"],

     "图片":[".jpeg",".jpg",".png",".gif",".bmp",".psd",".html"],

     "文档":[".txt",".pdf",".doc",".docx",".xlsx",".pptx"],

     "压缩":[".zip",".rar",".7z",".jar"],

    }

    path = "D:\\桌面"

    dirs = os.listdir(path)

    filename="桌面缓冲文件"+time.strftime('%Y:%m:%d',time.localtime(time.time())).replace(":", "_")

    filepath="D:\\Source_SBUF\\"+filename

    os.mkdir(filepath)

    for file in dirs:

        fname,ext = os.path.splitext(file)

        for d,exts in formats.items():

            if ext in exts:

                shutil.move(path+"\\"+file,filepath+"\\"+file)

                print(ext)

    以上就是python电脑桌面中整理exe程序的方法,希望对大家有所帮助。更多Python学习指路:python基础教程

    本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

    专题推荐:python
    上一篇:python如何转换为私有属性 下一篇:python网页中下拉框的操作

    相关文章推荐

    • 什么是网络协议• python中的去除重复项的操作• python中少见的函数map()和partial()• python的sort()排序方法• Python中的文件读写-理论知识

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网