批量恢复文件的Py脚本
生活随笔
收集整理的這篇文章主要介紹了
批量恢复文件的Py脚本
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
為什么80%的碼農都做不了架構師?>>> ??
在兩個項目中可能要復用文件,源目錄下的文件改動后要更新到目標目錄下,而經過整理后目標文件可能在不同的子目錄中。
今天在Win7虛擬機中使用xcopy srcpath destpath /U/Y同步Mac下的兩個項目時,文件全變為小寫了,因此想寫個腳本自動同步、保留大小寫。
#!/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)運行 python sync.py srcpath/somepath 就恢復文件名大小寫了,以后可自動同步到任意子目錄!
此文件已在GitHub開源
轉載于:https://my.oschina.net/rhcad/blog/264290
總結
以上是生活随笔為你收集整理的批量恢复文件的Py脚本的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 家用烤箱哪个牌子好?家用电烤箱的危害
- 下一篇: Cookie application s