当前位置:   article > 正文

Python_检查文件名是否规范(修改版)_python 正则表达式 文件名是否合法

python 正则表达式 文件名是否合法
  1. # coding=utf-8
  2. import os
  3. import os.path
  4. import re
  5. import array
  6. import cmd
  7. import pdb
  8. import pickle
  9. import tempfile
  10. import subprocess
  11. # rootPath = os.getcwd()
  12. # print rootPath
  13. rootPath = raw_input('The Check Path:')
  14. nonCheckDir = raw_input('The Non Check DirName(DirName1;DirName2):')
  15. nonCheckDirList = []
  16. if nonCheckDir:
  17. nonCheckDirList = nonCheckDir.split(';')
  18. # 路径字典
  19. pathDic = {}
  20. # 新建文件夹 os.path.isdir(rootdir+'/logout') 判断指定目录下该文件夹是否存在
  21. if not os.path.isdir(rootPath+'/logout'):
  22. os.makedirs(rootPath + '/logout')
  23. logPath=os.path.join(rootPath,'logout')
  24. nonstandard_filename_path = open(logPath+'/nonstandard_filename_path.txt','w')
  25. # 标准的符号库
  26. num = "0123456789"
  27. word = "abcdefghijklmnopqrstuvwxyz"
  28. sym = "_."
  29. # 符号库
  30. symBank = []
  31. for key in word:
  32. symBank.append(key)
  33. for key in num:
  34. symBank.append(key)
  35. for key in sym:
  36. symBank.append(key)
  37. def GetAllDir(getPath):
  38. # print (getPath)
  39. paths = os.listdir(getPath)
  40. for dirName in paths:
  41. dirPath = os.path.join(getPath,dirName)
  42. if os.path.isdir(dirPath) and dirName != '.svn':
  43. # print dirPath
  44. relPath = dirPath[len(rootPath)+1:len(dirPath)]
  45. # print relPath
  46. if not nonCheckDirList.__contains__(relPath):
  47. pathDic[relPath] = dirPath
  48. GetAllDir(dirPath)
  49. def GetAllFile(getPath):
  50. files = os.listdir(getPath)
  51. for fileName in files:
  52. filePath = os.path.join(getPath,fileName)
  53. if fileName.endswith('.png') or fileName.endswith('.PNG'):
  54. fileName = fileName[0:fileName.index('.')]
  55. if not set(fileName).issubset(symBank):
  56. # print fileName
  57. # print filePath
  58. nonstandard_filename_path.write(filePath + '\n')
  59. else:
  60. # (r'_[\d]*[x|X][\d]*\d') 正则表达式 (_100x100&
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/204073
推荐阅读
相关标签
  

闽ICP备14008679号