最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

對Python 檢查文件名是否規(guī)范的實例詳解

 更新時間:2019年06月10日 12:03:10   作者:愚公丨Acmen  
今天小編就為大家分享一篇對Python 檢查文件名是否規(guī)范的實例詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

如下所示:

# coding=utf-8
import os
import os.path
import re
import array
import cmd
import pdb
import pickle
import tempfile
import subprocess
 
 
# rootPath = os.getcwd()
# print rootPath
rootPath = raw_input('The Check Path:')
nonCheckDir = raw_input('The Non Check DirName(DirName1;DirName2):')
nonCheckDirList = []
if nonCheckDir:
  nonCheckDirList = nonCheckDir.split(';')
# 路徑字典
pathDic = {}
 
# 新建文件夾 os.path.isdir(rootdir+'/logout') 判斷指定目錄下該文件夾是否存在
if not os.path.isdir(rootPath+'/logout'):
  os.makedirs(rootPath + '/logout')
logPath=os.path.join(rootPath,'logout')
 
nonstandard_filename_path = open(logPath+'/nonstandard_filename_path.txt','w')
 
# 標(biāo)準(zhǔn)的符號庫
num = "0123456789"
word = "abcdefghijklmnopqrstuvwxyz"
sym = "_."
# 符號庫
symBank = []
for key in word:
  symBank.append(key)
for key in num:
  symBank.append(key)
for key in sym:
  symBank.append(key)
 
def GetAllDir(getPath):
  # print (getPath)
  paths = os.listdir(getPath)
  for dirName in paths:
    dirPath = os.path.join(getPath,dirName)
    if os.path.isdir(dirPath) and dirName != '.svn':
      # print dirPath
      relPath = dirPath[len(rootPath)+1:len(dirPath)]
      # print relPath
      if not nonCheckDirList.__contains__(relPath):
        pathDic[relPath] = dirPath
        GetAllDir(dirPath)
 
def GetAllFile(getPath):
  files = os.listdir(getPath)
  for fileName in files:
    filePath = os.path.join(getPath,fileName)
    if fileName.endswith('.png') or fileName.endswith('.PNG'):
      fileName = fileName[0:fileName.index('.')]
      if not set(fileName).issubset(symBank):
        # print fileName
        # print filePath
        nonstandard_filename_path.write(filePath + '\n')
      else:
        # (r'_[\d]*[x|X][\d]*\d') 正則表達(dá)式 (_100x100)
        sign = re.search(r'_[\d]*[x|X][\d]*\d',fileName,re.M|re.I)
        if sign:
          nonstandard_filename_path.write(filePath + '\n')
 
if __name__ == '__main__':
  print ('main')
  pathDic['curPath'] = rootPath
  GetAllDir(rootPath)
  for key in pathDic:
    # print key
    GetAllFile(pathDic[key])
 
  # line = "image_500100000"
  # obj = re.search(r'_[\d]*[x|X][\d]*\d',line,re.M|re.I)
  # line = line.replace(obj.group(),'=')
  # if obj:
  #   print obj.group()
  # else:
  #   print ("==-")
  # line1 = "image_500x100"
  # obj1 = re.search(r'[a-z0-9_]*',line1,re.M)
  # print obj1.group()

新建bat后綴文件

find_nonstandard_name.exe -c
@pause

修改后腳本

# coding=utf-8
import os
import os.path
import re
import array
import cmd
import pdb
import pickle
import tempfile
import subprocess
import sys
import getopt
 
rootPath = ""
nonCheckDirList = sys.argv[1:]
opts, args = getopt.getopt(sys.argv[1:],"cs:",["cPath="])
for opt,arg in opts:
  if opt == '-c':
    rootPath = os.getcwd()
  elif opt in ("-s","--cPath"):
    rootPath = arg
# 路徑字典
pathDic = {}
 
# 新建文件夾 os.path.isdir(rootdir+'/logout') 判斷指定目錄下該文件夾是否存在
if not os.path.isdir(rootPath+'/logout'):
  os.makedirs(rootPath + '/logout')
logPath=os.path.join(rootPath,'logout')
 
nonstandard_filename_path = open(logPath+'/nonstandard_filename_path.txt','w')
 
def GetAllDir(getPath):
  # print (getPath)
  paths = os.listdir(getPath)
  for dirName in paths:
    dirPath = os.path.join(getPath,dirName)
    if os.path.isdir(dirPath) and dirName != '.svn':
      # print dirPath
      relPath = dirPath[len(rootPath)+1:len(dirPath)]
      # print relPath
      if not nonCheckDirList.__contains__(relPath):
        pathDic[relPath] = dirPath
        GetAllDir(dirPath)
 
def GetAllFile(getPath):
  files = os.listdir(getPath)
  for fileName in files:
    filePath = os.path.join(getPath,fileName)
    if fileName.endswith('.png') or fileName.endswith('.PNG'):
      fileName = fileName[0:fileName.index('.')]
      firstSign = re.search(r'^[a-z0-9_]*$',line1,re.M)
      if firstSign:
        # print filePath
        # (r'_[\d]*[x|X][\d]*\d') 正則表達(dá)式 (_100x100)
        sign = re.search(r'_[\d]*[x|X][\d]*\d', fileName, re.M | re.I)
        if sign:
          print fileName
          nonstandard_filename_path.write(filePath + '\n')
      else:
        print fileName
        nonstandard_filename_path.write(filePath + '\n')
 
if __name__ == '__main__':
  print ('main')
  pathDic['curPath'] = rootPath
  GetAllDir(rootPath)
  for key in pathDic:
    # print key
    GetAllFile(pathDic[key])

添加檢查文件重名功能

# coding=utf-8
import os
import os.path
import re
import array
import cmd
import pdb
import pickle
import tempfile
import subprocess
import sys
import getopt
 
nonCheckDirList = sys.argv[1:]
rootPath = os.getcwd()
checkRepetPathList = []
if nonCheckDirList:
  rootPath = os.path.realpath(os.path.join(os.getcwd(),nonCheckDirList[0]))
  if nonCheckDirList[0] == "./":
    rootPath = os.getcwd()
  for _path in nonCheckDirList:
    # -- 檢查重命名路徑
    _cmdRepet = _path[0:2]
    if _cmdRepet == "/r":
      repetPath = _path[len(_cmdRepet):len(_path)]
      print repetPath
      checkRepetPathList.append(repetPath)
print rootPath + '\n'
# 路徑字典
pathDic = {}
# 重名路徑字典
repetDic = {}
# 新建文件夾 os.path.isdir(rootdir+'/logout') 判斷指定目錄下該文件夾是否存在
 
# if not os.path.isdir(rootPath+'/logout'):
#   os.makedirs(rootPath + '/logout')
# logPath=os.path.join(rootPath,'logout')
logPath = os.getcwd()
nonstandard_filename_path = open(logPath+"\\"+u"不規(guī)范命名文件".encode("GBK") + ".txt",'w')
 
def GetAllDir(getPath):
  # print (getPath)
  paths = os.listdir(getPath)
  for dirName in paths:
    dirPath = os.path.join(getPath,dirName)
    if os.path.isdir(dirPath) and dirName != '.svn':
      # print dirPath
      relPath = dirPath[len(rootPath)+1:len(dirPath)]
      # print relPath
      if not nonCheckDirList.__contains__(relPath):
        pathDic[relPath] = dirPath
        GetAllDir(dirPath)
 
def GetAllFile(getPath):
  files = os.listdir(getPath)
  for fileName in files:
    filePath = os.path.join(getPath,fileName)
    if fileName.endswith('.png') or fileName.endswith('.PNG'):
      fileName = fileName[0:fileName.index('.')]
      firstSign = re.search(r'^[a-z0-9_]*$',fileName,re.M)
      if firstSign:
        # print filePath
        # (r'_[\d]*[x|X][\d]*\d') 正則表達(dá)式 (_100x100)
        sign = re.search(r'_[\d]*[x|X][\d]*\d', fileName, re.M | re.I)
        if sign:
          print fileName
          nonstandard_filename_path.write(filePath + '\n')
      else:
        print fileName
        nonstandard_filename_path.write(filePath + '\n')
 
def CheckRepetFile(getPath):
  if checkRepetPathList:
    paths = os.listdir(getPath)
    for dirName in paths:
      dirPath = os.path.join(getPath, dirName)
      if os.path.isdir(dirPath) and dirName != '.svn':
        # print dirPath
        relPath = dirPath[len(rootPath) + 1:len(dirPath)]
        # print relPath
        repetDic[relPath] = dirPath
        CheckRepetFile(dirPath)
 
 
imageList = []
repetImagePath = []
def GetCheckRepetFile(getPath):
  files = os.listdir(getPath)
  for fileName in files:
    filePath = os.path.join(getPath, fileName)
    if fileName.endswith('.png') or fileName.endswith('.PNG'):
      # print filePath
      imageList.append(fileName)
      repetImagePath.append(filePath)
 
repet_filename_path = open(logPath+"\\"+u"重復(fù)命名文件".encode("GBK") + ".txt",'w')
 
if __name__ == '__main__':
  # print ('main')
  pathDic['curPath'] = rootPath
  GetAllDir(rootPath)
  for key in pathDic:
    # print key
    GetAllFile(pathDic[key])
  print '\n' + "The Logout Path:" + logPath+"\\"+u"不規(guī)范命名文件".encode("GBK") + ".txt"
 
 
  repetDic['curPath'] = rootPath
  # 檢查重復(fù)文件路徑列表
  for __path in checkRepetPathList:
    _repetPath = os.path.join(rootPath, __path)
    CheckRepetFile(_repetPath)
  # 遍歷路徑獲得所有圖片
  for key in repetDic:
    GetCheckRepetFile(repetDic[key])
  _newImageList = []
  for image in imageList:
    repetCount = imageList.count(image)
    if repetCount > 1 :
      if not image in _newImageList:
        _newImageList.append(image)
  for repetImage in _newImageList:
    print repetImage
    repet_filename_path.write(repetImage + '\n')
    for repetPathPath in repetImagePath:
      fileNameName = os.path.basename(repetPathPath)
      if repetImage == fileNameName:
        repet_filename_path.write(repetPathPath + '\n')
        # print repetPathPath
  print '\n' + "The Logout Path:" + logPath+"\\"+u"重復(fù)命名文件".encode("GBK") + ".txt"
 
 
 

以上這篇對Python 檢查文件名是否規(guī)范的實例詳解就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • python中dropna()函數(shù)的作用舉例說明

    python中dropna()函數(shù)的作用舉例說明

    這篇文章主要給大家介紹了關(guān)于python中dropna()函數(shù)的相關(guān)資料,dropna()是pandas庫中的一個函數(shù),用于刪除DataFrame中的缺失值,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-11-11
  • Django文件存儲 自己定制存儲系統(tǒng)解析

    Django文件存儲 自己定制存儲系統(tǒng)解析

    這篇文章主要介紹了Django文件存儲 自己定制存儲系統(tǒng)解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-08-08
  • Python包裝異常處理方法

    Python包裝異常處理方法

    這篇文章主要介紹了Python包裝異常處理方法,相比java,python的異常和java中不同,python主要是防止程序異常被中止。一旦被catch后它還行往下執(zhí)行,本文就分享python相關(guān)的異常處理方法,需要的小伙伴可以參考一下
    2022-06-06
  • python實現(xiàn)將多個文件分配到多個文件夾的方法

    python實現(xiàn)將多個文件分配到多個文件夾的方法

    今天小編就為大家分享一篇python實現(xiàn)將多個文件分配到多個文件夾的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-01-01
  • python測試mysql寫入性能完整實例

    python測試mysql寫入性能完整實例

    這篇文章主要介紹了python測試mysql寫入性能完整實例,具有一定借鑒價值,需要的朋友可以參考下
    2018-01-01
  • Python使用struct庫的用法小結(jié)

    Python使用struct庫的用法小結(jié)

    struct模塊執(zhí)行Python值和以Python?bytes表示的C結(jié)構(gòu)體之間的轉(zhuǎn)換,這可以用于處理存儲在文件中或來自網(wǎng)絡(luò)連接以及其他源的二進(jìn)制數(shù)據(jù),下面介紹下Python使用struct庫的用法,感興趣的朋友一起看看吧
    2022-05-05
  • python3安裝OCR識別庫tesserocr過程圖解

    python3安裝OCR識別庫tesserocr過程圖解

    這篇文章主要介紹了python3安裝OCR識別庫tesserocr過程圖解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-04-04
  • python按行讀取文件,去掉每行的換行符\n的實例

    python按行讀取文件,去掉每行的換行符\n的實例

    下面小編就為大家分享一篇python按行讀取文件,去掉每行的換行符\n的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-04-04
  • pytorch中的named_parameters()和parameters()

    pytorch中的named_parameters()和parameters()

    這篇文章主要介紹了pytorch中的named_parameters()和parameters()使用方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-09-09
  • 利用Python實現(xiàn)普通視頻變成動漫視頻

    利用Python實現(xiàn)普通視頻變成動漫視頻

    這篇文章主要為大家詳細(xì)介紹了如何利用Python語言實現(xiàn)普通視頻變成動漫視頻效果,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解一下
    2022-08-08

最新評論

久治县| 临洮县| 湛江市| 石渠县| 那曲县| 通海县| 石渠县| 射阳县| 凉城县| 潍坊市| 双鸭山市| 县级市| 怀来县| 大宁县| 临澧县| 扬中市| 临朐县| 樟树市| 贺兰县| 东台市| 杭锦后旗| 太和县| 海门市| 虎林市| 山阴县| 抚宁县| 元氏县| 石阡县| 章丘市| 宁陕县| 牟定县| 织金县| 京山县| 麻江县| 黎川县| 洪泽县| 武功县| 久治县| 建昌县| 湘阴县| 孟村|