批量恢复文件的Py脚本
生活随笔
收集整理的這篇文章主要介紹了
批量恢复文件的Py脚本
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
為什么80%的碼農(nóng)都做不了架構(gòu)師?>>> ??
在兩個(gè)項(xiàng)目中可能要復(fù)用文件,源目錄下的文件改動(dòng)后要更新到目標(biāo)目錄下,而經(jīng)過整理后目標(biāo)文件可能在不同的子目錄中。
今天在Win7虛擬機(jī)中使用xcopy srcpath destpath /U/Y同步Mac下的兩個(gè)項(xiàng)目時(shí),文件全變?yōu)樾懥?#xff0c;因此想寫個(gè)腳本自動(dòng)同步、保留大小寫。
#!/usr/bin/env python # -*- coding: utf-8 -*- # sync.py by rhcadimport os, sys, shutildef replacefiles(srcdir, dstdir, fn):dstfile = os.path.join(dstdir, fn.lower())if os.path.isfile(dstfile) and os.path.exists(dstfile):os.remove(dstfile)shutil.copy(os.path.join(srcdir, fn), os.path.join(dstdir, fn))print(dstfile)returnfor fn2 in os.listdir(dstdir):dstfile = os.path.join(dstdir, fn2)if os.path.isdir(dstfile):replacefiles(srcdir, dstfile, fn)if __name__=="__main__":srcdir = sys.argv[1]dstdir = os.path.abspath('.')for fn in os.listdir(srcdir):replacefiles(srcdir, dstdir, fn)運(yùn)行 python sync.py srcpath/somepath 就恢復(fù)文件名大小寫了,以后可自動(dòng)同步到任意子目錄!
此文件已在GitHub開源
轉(zhuǎn)載于:https://my.oschina.net/rhcad/blog/264290
總結(jié)
以上是生活随笔為你收集整理的批量恢复文件的Py脚本的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 家用烤箱哪个牌子好?家用电烤箱的危害
- 下一篇: Cookie application s