Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Program to clean Directories (sort them based on the Well name)
- # Comment/uncomment between shutil.copytree and shutil.move to copy and move
- __date__ = "June 14, 2019"
- __version = "1.0"
- # Import the modules
- import shutil # For os-independant directory management
- import re # Regular expression
- import os # For os related functions
- # Set the source (containing all well dirs) and destination directory
- srcDirPath = "src"
- destDirPath = "dst"
- # This regular expression assumes all the dirs will have the same
- # pattern like sometext_wellname_sometext
- WellNames = [re.findall(r"_(.*?)_", i)[0] for i in os.listdir(srcDirPath)]
- for well in set(WellNames): # set function to get unique well-names
- # Create Well directory in the destination
- destWellDir = "%s/%s" % (destDirPath, well)
- os.mkdir(destWellDir)
- for _dir in os.listdir(srcDirPath):
- if well in _dir:
- source = "%s/%s" % (srcDirPath, _dir)
- target = "%s/%s" % (destWellDir, _dir)
- shutil.copytree(source ,target)
- # shutil.move(source, target)
- # EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement