国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

腳本之家,腳本語言編程技術及教程分享平臺!
分類導航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

香港云服务器
服務器之家 - 腳本之家 - Python - 用python批量移動文件

用python批量移動文件

2021-08-25 00:18風中狂笑 Python

這篇文章主要介紹了如何用python批量移動文件,幫助大家更好的理解和使用python,感興趣的朋友可以了解下

我是用來移動圖片的,其他格式的文檔也是可以的,改下后綴列表就可以了

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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')

然后再刪除空文件夾

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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批量移動文件的詳細內容,更多關于python批量移動文件的資料請關注服務器之家其它相關文章!

原文鏈接:https://www.cnblogs.com/dogingate/p/12524319.html

延伸 · 閱讀

精彩推薦
1274
主站蜘蛛池模板: 天堂资源 | 欧美黄色成人 | 国产又色又爽又黄又免费 | 国产精品久久久久久久午夜 | 国产成人欧美一区二区三区的 | 毛片91 | 亚洲激情在线 | 在线免费观看激情视频 | 秋霞特色aa大片 | 羞羞网站在线 | 久久99精品久久久久久国产越南 | 激情小视频 | 亚洲影视一区 | 国产高清在线精品一区二区三区 | 欧美成人精品一区二区男人看 | 国产欧美日韩综合精品一区二区 | 婷婷激情久久 | 毛片视频网站在线观看 | 久久中文字幕一区 | 91久久久久久 | 日韩精品1区2区3区 国产日韩在线视频 | 亚洲精品第一 | 久久久久国产精品 | 欧美日韩视频在线 | 亚洲高清视频在线 | 欧美精品www| 国产精品一区久久久 | 国产99久久精品一区二区永久免费 | 欧美中文字幕在线观看 | 日韩精品中文字幕在线观看 | 亚洲精品视频在线观看免费 | 久久久久久久久久久久久九 | 久久99视频 | 欧美a级免费看 | 精品视频一区二区三区 | 亚洲国产精品久久久久久 | 欧美日韩免费 | 国产成人精品久久 | 亚洲欧洲精品成人久久奇米网 | 亚洲精品一区二区在线观看 | 99精品国产一区二区青青牛奶 |