当前位置: 首页 > news >正文

苏州企业做网站廊坊seo优化

苏州企业做网站,廊坊seo优化,学做网站赚钱方法,苏州免费发布信息网站完成了文件自动分类的操作后,我们一起来复习下: 首先,获取文件夹中所有文件名称,用 os.path.join() 函数拼接出要移动到的目标地址。然后,使用 os.path.exists() 函数判断目标文件夹是否存在,不存在用 os.m…

完成了文件自动分类的操作后,我们一起来复习下:

首先,获取文件夹中所有文件名称,用 os.path.join() 函数拼接出要移动到的目标地址。然后,使用 os.path.exists() 函数判断目标文件夹是否存在,不存在用 os.mkdir() 创建文件夹。再者,使用 os.path.isdir() 函数判断是否为文件夹。最后,当不是文件夹时,使用 shutil.move() 函数移动。

# 使用import导入os模块

import os

# 使用import导入shutil模块

import shutil

# 将阿文的下载文件夹路径 /Users/yequ/Desktop 赋值给变量desktopPath

desktopPath = "/Users/yequ/Desktop"

# 使用os.listdir()函数获取该路径下所有的文件(夹),并赋值给变量allItems

allItems = os.listdir(desktopPath)

# 使用for循环遍历所有文件(夹)

for item in allItems:

    # 获取文件后缀名

    extension = os.path.splitext(item)[1].lower()

    # 定义一个变量targetPath,用来表示准备移动到的文件夹路径

    targetPath = ""

    if extension in [".jpg", ".jpeg", ".gif", ".png", ".bmp"]:

        # 使用os.path.join()函数拼接分类文件夹路径:图片文件

        # 并赋值给变量targetPath

        targetPath = os.path.join(desktopPath, "图片文件")

    elif extension in [".avi", ".mp4", ".wmv", ".mov", ".flv"]:

        # 使用os.path.join()函数拼接分类文件夹路径:视频文件

        # 并赋值给变量targetPath

        targetPath = os.path.join(desktopPath, "视频文件")

    elif extension in [".wav", ".mp3", ".mid", ".ape", ".flac"]:

        # 使用os.path.join()函数拼接分类文件夹路径:音频文件

        targetPath = os.path.join(desktopPath, "音频文件")

    elif extension in [".pdf"]:

        # 使用os.path.join()函数拼接分类文件夹路径:PDF文件

        targetPath = os.path.join(desktopPath, "PDF文件")

    elif extension in [".docx", ".doc"]:

        # 使用os.path.join()函数拼接分类文件夹路径:Word文件

        targetPath = os.path.join(desktopPath, "Word文件")

    elif extension in [".xlsx", ".xls"]:

        # 使用os.path.join()函数拼接分类文件夹路径:Excel文件

        targetPath = os.path.join(desktopPath, "Excel文件")

    elif extension in [".pptx", ".ppt"]:

        # 使用os.path.join()函数拼接分类文件夹路径:PPT文件

        targetPath = os.path.join(desktopPath, "PPT文件")

    else:

        # 使用os.path.join()函数拼接分类文件夹路径:其他文件

        targetPath = os.path.join(desktopPath, "其他文件")

    # 判断当如果目标文件夹不存在

    if not os.path.exists(targetPath):

        # 使用os.mkdir()函数创建文件夹

        os.mkdir(targetPath)

    # 使用os.path.join()函数拼接desktopPath和文件名

    # 并赋值给变量itemPath

    itemPath = os.path.join(desktopPath, item)

    # 判断当itemPath不是文件夹时。

    if not os.path.isdir(itemPath):

        # 使用shutil.move()函数移动文件到targetPath路径

        shutil.move(itemPath, targetPath)

http://www.mmbaike.com/news/47824.html

相关文章:

  • 做网站主页图片一般多少m成都本地推广平台
  • wap网站苏州关键词优化排名推广
  • 建设银行山东分行社会招聘网站宁波免费seo排名优化
  • 南宁定制网站建设搜索引擎优化自然排名
  • 武汉找人做网站千锋教育学费一览表
  • 网站建设 税种seo外链收录
  • 建设大型视频网站需要的资金量网络推广营销技巧
  • 腾讯企业邮箱邮箱广州seo托管
  • 企业网站源码 html百度主页入口
  • 企业网站建设 哪个公司做得好win10优化软件
  • 做网站的收益在哪中国时事新闻网
  • 做网站要会写代码吗品牌公关
  • 北京做网站制作公司微信广告推广价格表
  • 建二手车网站黑帽seo技术
  • 制作公司网站多少钱中国域名网官网
  • 网站图片属性是什么爱站长工具综合查询
  • 投资公司网站建设意义推广普通话奋进新征程演讲稿
  • 个人网页设计思路怎么写百度seo快速提升排名
  • 织梦网站怎么做伪静态页面南宁seo公司哪家好
  • 政府网站配色腾讯搜索引擎入口
  • 东凤网站广告投放运营主要做什么
  • 去什么网站可以做ctf的题目免费网站推广网站在线
  • 有关电商网站开发的实习报告怎么优化自己公司的网站
  • 常德市网站建设国内的搜索引擎排名
  • wordpress 怎么切换主题seo顾问服务福建
  • 门户网站建设公司哪家好产品推广运营方案
  • 微信朋友圈推广怎么做网站网站怎么快速被百度收录
  • 陕西中洋建设有限公司网站移动广告平台
  • 手机社区网站模板网站关键词推广价格
  • 协会网站信息平台建设seo怎么做排名