-1

I have to copy folders from one directory to another directory (Copy only that folders that I have included in a txt file)

I am able to copy all folders but how to copy only specific folders? Eg: I want to copy folder that starts with 111, so it should only copy the folder that starts with 111. So basically, I have to include certain folder names in a txt file and use that text file in my python code so that it would only copy the folders which are included in the txt file.

from distutils.dir_util import copy_tree

fromDirectory = "/a/b/c"

toDirectory = "/x/y/z"

copy_tree(fromDirectory, toDirectory)
Delrius Euphoria
  • 14,910
  • 3
  • 15
  • 46
MatrixGuy
  • 1
  • 1

1 Answers1

0

You could use glob so to grab the files with the specific marker you're interested in:

import glob
import os

files = glob.glob('path/to/dir/111**')

for f in files:
    os.rename(f, os.path.join('path/to/new/dir', os.path.split(f)[1]))
Michael Green
  • 719
  • 6
  • 15