Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import shutil
- src = r"C:\Users\Gali\Documents\A"
- dst = r"C:\Users\Gali\Documents\C"
- txt_only = r"C:\Users\Gali\Documents\T"
- if not os.path.exists(dst):
- os.mkdir(dst)
- def copy_tree(src, dst, txt_only = r"C:\Users\Gali\Documents\T"):
- for item in os.listdir(src):
- s = os.path.join(src, item)
- d = os.path.join(dst, item)
- if item.lower().endswith(".txt"):
- t = os.path.join(txt_only, item)
- if not os.path.exists(t):
- shutil.copy2(s, t)
- if os.path.isdir(s):
- shutil.copytree(s, d)
- copy_tree(s, d, txt_only)
- else:
- shutil.copy2(s, d)
- copy_tree(src,dst)
- """copy everything from directory to an existing directory
- def copytree(src, dst, txt_only):
- for item in os.listdir(src):
- s = os.path.join(src, item)
- d = os.path.join(dst, item)
- if item.lower().endswith(".txt"):
- t = os.path.join(txt_only, item)
- if not os.path.exists(t):
- shutil.copy2(s, t)
- if os.path.isdir(s):
- shutil.copytree(s, d)
- else:
- shutil.copy2(s, d)
- #copy everything from directory to an existing directory
- def copytree(src, dst, txt_only = r"C:\Users\Gali\Documents\T"):
- for item in os.listdir(src):
- s = os.path.join(src, item)
- s = s.replace(r"\\", r"/")
- print(item)
- print(s)
- d = os.path.join(dst, item)
- d = d.replace(r"\\", r"/")
- print(d)
- print(dst)
- t = os.path.join(txt_only, item)
- print(t)
- if item.endswith(".txt"):
- t = t.replace(r"\\", r"/")
- shutil.copy2(s, t)
- if os.path.isdir(s):
- print("yes")
- shutil.copytree(s, d)
- else:
- shutil.copy2(s, d)
- #copy everything from directory to an existing directory
- def copy_tree(src, dst, txt_only = r"C:\Users\Gali\Documents\T\\"):
- for item in os.listdir(src):
- s = os.path.join(src, item)
- s = s.replace(r"\\", r"/")
- d = os.path.join(dst, item)
- d = d.replace(r"\\", r"/")
- t = os.path.join(txt_only, item)
- t = t.replace(r"\\", r"/")
- if item.endswith(".txt"):
- shutil.copy(s, t)
- if os.path.isdir(s):
- shutil.copy(s, d)
- copy_tree(s, d)
- else:
- shutil.copy(s, d)
- copy_tree(src,dst)"""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement