欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

利用python怎么批量移動文件-創(chuàng)新互聯(lián)

這篇文章將為大家詳細講解有關利用python怎么批量移動文件,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關知識有一定的了解。

目前創(chuàng)新互聯(lián)已為上千家的企業(yè)提供了網(wǎng)站建設、域名、網(wǎng)站空間網(wǎng)站托管運營、企業(yè)網(wǎng)站設計、南丹網(wǎng)站維護等服務,公司將堅持客戶導向、應用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
import os,shutil
import datetime
 
#將文件夾里的圖片全部移動到新文件夾中
#revised by Stephen Shen 2020-3-10 09:28:50
 
def renameFile(dstpath):
    fdirname,fbasename=os.path.split(dstpath)
    #文件名相同但大小不同
    fname,fext=os.path.splitext(fbasename)
    nowtime=datetime.datetime.now()               
    strtime=str(nowtime.year)+str(nowtime.month)+str(nowtime.day)+str(nowtime.hour)+str(nowtime.minute)
    newfbasename=fname+'-'+strtime+fext
    dstpath=os.path.join(fdirname,newfbasename)
    return dstpath
 
def moveFile(oldpath,newpath):
    if os.path.exists(newpath):
        newpath=renameFile(newpath)
    try:
        shutil.move(oldpath,newpath)
        print(oldpath+' is moved')
    except:
        print(oldpath+' is skipped')
 
inpath=r'K:\fileExtracted\imagesFromDocs'
 
outpath=r'K:\filesExtracted'
image_ext=['.JPG','.jpg','.png','.PNG','.jpeg','.wdp']
image_outpath=os.path.join(outpath,'image')
doc_ext=['.doc','.docx']
doc_outpath=os.path.join(outpath,'doc')
 
emf_ext=['.emf']
emf_outpath=os.path.join(image_outpath,'emf')
wmf_ext=['.wmf']
wmf_outpath=os.path.join(image_outpath,'wmf')
 
if not os.path.exists(outpath):
    os.makedirs(outpath)
if not os.path.exists(image_outpath):
    os.makedirs(image_outpath)
if not os.path.exists(doc_outpath):
    os.makedirs(doc_outpath)
if not os.path.exists(emf_outpath):
    os.makedirs(emf_outpath)
if not os.path.exists(wmf_outpath):
    os.makedirs(wmf_outpath)
 
 
 
for folder,subfolders,files in os.walk(inpath):
    for file in files:
        oldpath=os.path.join(folder,file)
 
        if os.path.splitext(file)[-1] in image_ext:
            newpath=os.path.join(image_outpath,file)
            moveFile(oldpath,newpath)
        elif os.path.splitext(file)[-1] in doc_ext:
            newpath=os.path.join(doc_outpath,file)
            moveFile(oldpath,newpath)
        elif os.path.splitext(file)[-1] in emf_ext:
            newpath=os.path.join(emf_outpath,file)
            moveFile(oldpath,newpath)
        elif os.path.splitext(file)[-1] in wmf_ext:
            newpath=os.path.join(wmf_outpath,file)
            moveFile(oldpath,newpath)
        else:
            continue       
 
print('done')

然后再刪除空文件夾

import os,shutil
 
#將文件夾里的空文件夾刪除
#revised by Stephen Shen 2020-3-8 17:50:24
 
inpath=r'E:\pics-moving\待分類照片'
 
for folder,subfolders,files in os.walk(inpath):
    if not os.listdir(folder):
        shutil.rmtree(folder)
        # print(folder+' is empyt')
        print(folder+' is deleted')
 
print('done')

關于利用python怎么批量移動文件就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

分享題目:利用python怎么批量移動文件-創(chuàng)新互聯(lián)
分享鏈接:http://www.aaarwkj.com/article4/dddsoe.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈網(wǎng)站策劃、品牌網(wǎng)站建設、軟件開發(fā)、ChatGPT、外貿(mào)網(wǎng)站建設

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站
韩国av电影免费观看| 亚洲永久免费黄色av| 日韩精品在线免费观看了| 日韩精品在线观看天堂| 婷婷五激情五月激情片| 国产视频一区2区三区| 日本中文有码在线观看| 久久精品人妻一区二区| 日韩 高清 一区二区| 国产亚洲欧美精品在线观看| 亚洲人妻av一区二区| 中文字幕乱码日韩一二三区| 免费啪啪视频一区二区| 亚洲男人的天堂久久精品| 欧美十八一区二区三区| 最近中文字幕免费手机版| 久久五月婷婷爱综合亚洲| 午夜91激情福利视频| 九七青青草视频在线观看| 国产丰满熟女视频免费| 久久久精品免费福利视频| 久久不卡高清免费av| 一级丰满少妇av大片| 在线免费观看日韩黄片| 少妇被又粗又硬猛烈进视频| 91久久精品国产一区| 成人av影视中文字幕 | 蜜臀在线免费观看av| 日本午夜视频在线观看| 日韩一区二区精品网站| 日韩精品国产专区一区| 激情四射五月天亚洲婷婷| 高清不卡一区二区在线观看| 久久午夜福利欧美视频| 91色老久久精品偷偷鲁无毒| 精品国产一区二区三区精品日韩| 亚洲av偷拍一区二区三区不卡| 性色av人妻中文一区二区| 啊啊啊用力好大视频| 亚洲精品av一区二区久久 | 日本大型午夜福利视频|