Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.46 KB | None | 0 0
  1. import os
  2. import shutil
  3. src = r"C:\Users\Gali\Documents\A"
  4. dst = r"C:\Users\Gali\Documents\C"
  5. txt_only = r"C:\Users\Gali\Documents\T"
  6.  
  7. if not os.path.exists(dst):
  8.     os.mkdir(dst)
  9.  
  10. def copy_tree(src, dst, txt_only = r"C:\Users\Gali\Documents\T"):
  11.     for item in os.listdir(src):
  12.         s = os.path.join(src, item)
  13.         d = os.path.join(dst, item)
  14.         if item.lower().endswith(".txt"):
  15.             t = os.path.join(txt_only, item)
  16.             if not os.path.exists(t):
  17.                 shutil.copy2(s, t)
  18.  
  19.         if os.path.isdir(s):
  20.             shutil.copytree(s, d)
  21.             copy_tree(s, d, txt_only)
  22.         else:
  23.             shutil.copy2(s, d)
  24.  
  25. copy_tree(src,dst)
  26.  
  27. """copy everything from directory to an existing directory
  28. def copytree(src, dst, txt_only):
  29.    for item in os.listdir(src):
  30.        s = os.path.join(src, item)
  31.        d = os.path.join(dst, item)
  32.        if item.lower().endswith(".txt"):
  33.            t = os.path.join(txt_only, item)
  34.            if not os.path.exists(t):
  35.                shutil.copy2(s, t)
  36.  
  37.        if os.path.isdir(s):
  38.            shutil.copytree(s, d)
  39.        else:
  40.            shutil.copy2(s, d)
  41.  
  42.  
  43. #copy everything from directory to an existing directory
  44. def copytree(src, dst, txt_only = r"C:\Users\Gali\Documents\T"):
  45.    for item in os.listdir(src):
  46.        s = os.path.join(src, item)
  47.        s = s.replace(r"\\", r"/")
  48.  
  49.  
  50.        print(item)
  51.        print(s)
  52.  
  53.        d = os.path.join(dst, item)
  54.        d = d.replace(r"\\", r"/")
  55.        print(d)
  56.        print(dst)
  57.  
  58.  
  59.        t = os.path.join(txt_only, item)
  60.        print(t)
  61.        if item.endswith(".txt"):
  62.            t = t.replace(r"\\", r"/")
  63.            shutil.copy2(s, t)
  64.  
  65.        if os.path.isdir(s):
  66.            print("yes")
  67.            shutil.copytree(s, d)
  68.        else:
  69.            shutil.copy2(s, d)
  70.  
  71.  
  72.  
  73.  
  74.  
  75. #copy everything from directory to an existing directory
  76. def copy_tree(src, dst, txt_only = r"C:\Users\Gali\Documents\T\\"):
  77.    for item in os.listdir(src):
  78.        s = os.path.join(src, item)
  79.        s = s.replace(r"\\", r"/")
  80.  
  81.        d = os.path.join(dst, item)
  82.        d = d.replace(r"\\", r"/")
  83.  
  84.        t = os.path.join(txt_only, item)
  85.        t = t.replace(r"\\", r"/")
  86.  
  87.        if item.endswith(".txt"):
  88.            shutil.copy(s, t)
  89.  
  90.        if os.path.isdir(s):
  91.            shutil.copy(s, d)
  92.            copy_tree(s, d)
  93.        else:
  94.            shutil.copy(s, d)
  95.  
  96. copy_tree(src,dst)"""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement