Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. # Program to clean Directories (sort them based on the Well name)
  2. # Comment/uncomment between shutil.copytree and shutil.move to copy and move
  3.  
  4. __date__ = "June 14, 2019"
  5. __version = "1.0"
  6.  
  7. # Import the modules
  8. import shutil # For os-independant directory management
  9. import re # Regular expression
  10. import os # For os related functions
  11.  
  12. # Set the source (containing all well dirs) and destination directory
  13. srcDirPath = "src"
  14. destDirPath = "dst"
  15.  
  16. # This regular expression assumes all the dirs will have the same
  17. # pattern like sometext_wellname_sometext
  18. WellNames = [re.findall(r"_(.*?)_", i)[0] for i in os.listdir(srcDirPath)]
  19.  
  20. for well in set(WellNames): # set function to get unique well-names
  21.  
  22. # Create Well directory in the destination
  23. destWellDir = "%s/%s" % (destDirPath, well)
  24. os.mkdir(destWellDir)
  25.  
  26. for _dir in os.listdir(srcDirPath):
  27. if well in _dir:
  28. source = "%s/%s" % (srcDirPath, _dir)
  29. target = "%s/%s" % (destWellDir, _dir)
  30. shutil.copytree(source ,target)
  31. # shutil.move(source, target)
  32.  
  33. # EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement