Questions tagged [copytree]

Use this tag for questions relevant to the `copytree()` function, from the shutil module of Python.

Quoting the ref:

shutil.copytree(src, dst, symlinks=False, ignore=None)

Recursively copy an entire directory tree rooted at src. The destination directory, named by dst, must not already exist; it will be created as well as missing parent directories. Permissions and times of directories are copied with copystat(), individual files are copied using shutil.copy2().

is used for questions that are using the shutil module of Python, and have to do with the act of copying an entire directory, with or without manipulating it (e.g. filtering it).

48 questions
0
votes
2 answers

copy subfolder without parent folders

I have the folder /a/b/c/d/ and I want to copy d/ into destination /dst/. However, shutil.copytree("/a/b/c/d", "/dst") produces /dst/a/b/c/d. I only want /dst, or even /dst/d would suffice, but I don't want all the intermediate folders. [edit] As…
Alex Shroyer
  • 3,499
  • 2
  • 28
  • 54
0
votes
1 answer

Debugging & possible causes of distutils.dir_util.copy_tree() doesn't exist or not a regular file

I have some simple code to import a csv file of Windows File Paths e.g."C:/Folder/SubFolder/folder1" to copy the contents and any subfolders to a new directory. When I run the code I get about 1/3 of my sample returning doesn't exist or not a…
mobcdi
  • 1,532
  • 2
  • 28
  • 49
0
votes
3 answers

Copy specific subdirectories by its name with Python

If I have a folder which has multiple subfolders, each has same structure sub1, sub2 and sub3: ├─a │ ├─sub1 │ ├─sub2 │ └─sub3 ├─b │ ├─sub1 │ ├─sub2 │ └─sub3 └─c ├─sub1 ├─sub2 └─sub3 ... I want to copy sub1 and sub2 if there are…
ah bon
  • 9,293
  • 12
  • 65
  • 148
0
votes
0 answers

Python 3.7.1 Copying all files from a single source into a list of folders created from a .xlsx

My story goes that I am going to continue getting a .xlsx file with a list of things. All of the things exist in a specific sheet. I have created a Tkinter to help select which sheet to choose from. From there, it creates a basic file structure…
0
votes
1 answer

How to convert the list to glob style pattern in python

I need to copy the files using shutil copytree with certain pattern. The patterns I am having as list. I converted the list to string using below method to pass in the copy tree ignore_pattern as below. def convert_list_to_str(pattern): patter =…
ArockiaRaj
  • 588
  • 4
  • 17
0
votes
0 answers

Python recurrent copy from folder work in linux but not in win systems

In my project a icreate a function for copy folder in recurrent mode from a path to another like this: def copytree(src, dst, symlinks=False, ignore=None): for item in os.listdir(src): s = os.path.join(src, item) d =…
Manuel Santi
  • 1,106
  • 17
  • 46
0
votes
0 answers

Import Shutil module arttribute

I tried to use shutil module and copytree attribute. But it is not working and the commands box is empty. I import copytree and still not working.
rmatinp
  • 1
  • 3
0
votes
1 answer

How to copy all files including subfolders using Python

i have tried many possibilities i have found on the net so far and i just can not get it working. I have this code: def copytree(src, dst, symlinks=False, ignore=None): if not os.path.exists(dst): os.makedirs(dst) for item in…
H123321
  • 138
  • 2
  • 11
0
votes
0 answers

Copy directory tree but with most recent files?

Related to my question here force doxygen to pick one from versioned files I'm looking for kind of very simple version control but name based . For sure it would be easier to just use vcs but i want to use it on binary files too ( about 1gb per…
bolek
  • 7
  • 3
0
votes
2 answers

How can I copy different file types in Python while keeping their directory structure

I'm new to using Spyder 2.3.0 and Python 3.4.1 I have a directory structure with sub directories. Unlike other examples on the web I want to select multiple file types and copy the directory structure across. I have tried below and it works but it…
Lost1e
  • 3
  • 4
0
votes
1 answer

Python: shutil.copytree , lack of ignore arg in python 2.5

Short of essentially rewriting copytree to accept an ignore callback, what is a simple way to achieve this in versions prior to python 2.6? (I don't want to stray from my debian packages)
andyortlieb
  • 2,326
  • 3
  • 21
  • 33
0
votes
1 answer

How to use shutil.copytree in case of whitespaces in a filename

I can't use shutil.copytree() when there are whitespaces in the filename. I think I have to use the raw string --> r'your-string' But how to implement this? EDIT: This is my code. import os import shutil import sys usb_folder =…
kame
  • 20,848
  • 33
  • 104
  • 159
0
votes
1 answer

non-recursive shutil.copytree in python

I am pretty new to using python and am trying to create a new folder structure for some files. I am using os, shutil, and copytree to do the following: ORIGINAL FOLDER STRUCTURE: top_folder/ batch1/ 1.tif 1.xml 2.tif …
Kim
  • 15
  • 6
0
votes
2 answers

Python shutil.copytree function not working

I feel like I am either missing something basic here are something wonky is going on. I have read the docs and understand that copytree must specify both a source path and a destination path. I am struggling with the destination part. My code is…
papezjustin
  • 2,223
  • 6
  • 24
  • 31
-1
votes
1 answer

Cannot get Python shutil.copytree ignore pattern to work

I am somewhat new to Python but not coding. I'm trying to get copytree to work, and it does, but it will not work with ignore_patterns. I think it's because I don't know how to send a variable list of files to the ignore_patterns() function. I tried…