python how to find directories by name and the name start by some fixed character and end by random characters.


SUBMITTED BY: alemotta

DATE: Dec. 8, 2017, 12:17 p.m.

FORMAT: Text only

SIZE: 706 Bytes

HITS: 147

  1. #python how to find directories by name and the name start by some fixed character and end by random characters.
  2. import os
  3. import re
  4. bdire = input("base dire : ")
  5. myext = input("type folder name : ")
  6. txtoutput = input("file output : ")
  7. reg_compile = re.compile(myext +".*")
  8. def sessionSsave(nSess):
  9. sessFile = open(txtoutput,"a+")
  10. #sessnum = sessFile.readlines()
  11. #numer = len(sessnum)
  12. sessFile.write(str(nSess))
  13. sessFile.close()
  14. for root, dirs, filenames in os.walk(bdire):
  15. for dir in dirs:
  16. if reg_compile.search(dir):
  17. print(os.path.join(root,dir))
  18. tosave = os.path.join(root, dir)+"\r\n"
  19. sessionSsave(tosave)

comments powered by Disqus