By using topdown=False, we tell os.walk to traverse the folder tree depth-first. my code: """ This script reads XML files in a folder and moves the files to different folders based on the value of the <tPag> tag. Step 4: Just make sure that All subfolders option is enabled. This is very similar to the call() method with a similar set of arguments. Site design / logo 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. Asking for help, clarification, or responding to other answers. Move or Copy Files in Sub-folders to a Single Folder Method 1: Using Command Prompt Method 2: Using the Libraries feature in Windows Method 3: Using Windows Search Method 4: Using the 7-Zip file manager Method 5: Using Total Commander Making sure every file has been moved successfully RELATED: Move or Copy Files in Subfolders to a Single Folder How to Copy files or Folder without overwriting existing files? If your application runs on a different operating system, you must write a code that will run on a different OS without any issue. Shutil module in Python provides many functions of high-level operations on files and collections of files. Site design / logo 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. Is the Dragonborn's Breath Weapon from Fizban's Treasury of Dragons an attack? os.listdir(dir), lists all the files in the specified directory, dir, and os.path.join(a, b) is used to create a path by joining sub-paths a followed by b respectively. On Windows, the return value is that returned by the system shell after runningthe command. The copyfile() method is used to copy the contents of one file to another file. for f in listOfFiles: For example, If your application uses the shared resources, you should copy a file in blocking mode instead of asynchronously. It's the same process for moving subfolders, you would need to remove the file specific portions of the code. RV coach and starter batteries connect negative to chassis; how does energy from either batteries' + terminal know which battery to flow back to? I want all the jpg's in every subfolder to go to a single folder: d:\Completed Color Files. Copying Files using subprocess.check_output() method, list of all files present in the source folder. I want to copy the 1_ppt.csv to SIM1 folder, 2_ppt.csv to SIM2 folder,so on. dest: A string representing the path of the destination. source file's metadata. Please comment, share or like the post. The copy2() function in this code does one additional operation in addition to a copy() which is to keep the metadata. The parent folder here is the parent in relation to where the script is. By using our site, you It is used to recursively copy a file from one location to another. But the copyfile() only calls the copyfileobj() inside its implementation. Would the reflected sun's radiation melt ice in LEO? Syntax: os.path.join(path, *paths)Parameter:path: A path-like object representing a file system path. How to read multiple text files from a folder in Python?(Tkinter). Under the file path D:/src, I have images folders and its subfolders which have a regular structure as follows: I want to copy all .jpg files in Subfolder b from Folder A, B, C and so on to a new folder Subfolder b in D:/dst. (No, I knew about it for around _4 months, but I was too lazy to actually write the code ). Return Type: This method returns a string which represents the concatenated path components. shutil (shell utilities) module, provides option to copy the files recursively from src to dst. Thanks. How to move all files from one directory to another using Python ? How to move list of folders with subfolders using Python ? Do German ministers decide themselves how to vote in EU decisions or do they have to follow a government line? This indicates that both the source and the destination include the file. All the files will be copied in a single process. Doing this allows us to copy both files and directories using a single code. Agree How to choose voltage value of capacitors. Works perfectly fine. Create Destination Folder Example: Suppose the directory looks like this. @Nikolay the names of the folders are integers (1-9). Move all files and specific files from one directory to another using shutil module in Python By Rohan Harish In this tutorial, we will learn about moving files from one directory to another using Python's shutil module. fullPath = srcPath + / + f You can copy the contents of one folder to another using the shutil.copy (), shutil.copy2 () and shutil.copytree () methods of this module. Loop through folders/files Create new folder in output folder using name of MXD (This assumes output folder is in another location to the input folder.) Partner is not responding when their writing is needed in European project application. I want to move the 1st video file of all 9 folders into one new folder "folder 01", and so on. i can give you a hint ! shutil.copy () Python's shutil module provides a function shutil.copy () i.e. Thanks for sharing the code adrianp. How to create a list of files, folders, and subfolders in Excel using Python ? Here, we will see how to copy file from subfolder to one folder in Python. Python provides various methods to perform operations on the files and folders of the underlying operating system. copy the additional metadata namely timestamps of the source file to the destination, How to copy files in Python using shutil modules, The OS and subprocess module to copy files using the underlying operating systems shell command (, Store the source and destination directory path into two, In each iteration, concatenate the current file name with the source folder path. While the copy() and the copy2() methods both copy the contents of the file along with the metadata there are two significant differences between these two methods. Then, we also get a list of all the files & subfolders in that folder using os.listdir() function. How can I remove a key from a Python dictionary? Here, You can get Tutorials, Exercises, and Quizzes to practice and improve your Python skills. This allowed me to back everything out and start over. Affordable solution to train a team and make them project ready. With that, I then: loop the list of files and print their full path. Is variance swap long volatility of volatility? Jordan's line about intimate parties in The Great Gatsby? The system() method is again used to execute the script in the shell or an OS command. Find centralized, trusted content and collaborate around the technologies you use most. This article will discuss how to move all files from the subfolder to the main folder using Python. Return Value: This method returns a string which represents the path of newly created file. Use the copytree () method of a shutil module to copy the directory recursively. In total i have 9 folders, each folder holds 130 number of video files. How can I copy a file from one folder to another folder within a container in Docker? This module intends to replace several older modules and functions: This method could be used to execute any command that is passed as an argument to this method and the return value would be end status of the command that was executed. Below is the implementation. In this example, I have used two modules called shutil, and os. Economy picking exercise that uses two consecutive upstrokes on the same string, Rename .gz files according to names in separate txt-file. The function copytree() takes the argument ignore that allows specifying a function that returns a list of directories or files that should be ignored. If the destination exists but with a different name compared to the source file then the contents of the destination file will be overwritten. If we need to reverse the process, then what could be the approach. Method 1: Using shutil.copyfile () Using copyfile () method of shutil library we can easily copy a file from one location to other location. To get New Python Tutorials, Exercises, and Quizzes. I want to do the reverse of what you did. This tutorial will show you how to loop through folders and subfolders using Python and return the list of files. We are going to copy the file.txt in the base folder from the subfolder. How to use Glob() function to find files recursively in Python? It is created during the copy operation execution. While using PYnative, you agree to have read and accepted our Terms Of Use, Cookie Policy, and Privacy Policy. Sometimes we want to copy all files from one directory to another. Refer the following example. for subdir, dirs, files in os.walk (rootdir): for file in files: print (file) Which will print ALL of the files in the directory and subdirectories, then using this you can implement a check and use os.rename to rename the files accordingly. If the destination folder is not writable then PermissionError will be raised. By using our site, you ~Suzie Wagner, 1998, Click to share on Facebook (Opens in new window), Click to share on Twitter (Opens in new window), Click to share on LinkedIn (Opens in new window), Click to share on Reddit (Opens in new window), Click to email a link to a friend (Opens in new window). The number of distinct words in a sentence. How to copy Docker images from one host to another without using a repository? The methods are portable across different operating systems. A group of files and subdirectories is called a directory or folder. How to copy a table from one MySQL database to another? Connect and share knowledge within a single location that is structured and easy to search. Syntax: shutil.copytree(src, dst, symlinks = False, ignore = None, copy_function = copy2, ignore_dangling_symlinks = False)Parameters:src: A string representing the path of the source directory. Python comes with various modules that offer variety of ways to perform input/output operation and we will discuss them here. How to move all files from one directory to another using Python ? Tags: file, module, move, os, python, shutil, This worked like a charm and was exactly what I have been on the search for! To subscribe to this RSS feed, copy and paste this URL into your RSS reader. Permissions and times of directories are copied with copystat() and individual files are copied using shutil.copy2(). Initial directory hierarchy: folder1/ file1.gz filexyz.gz folder2/ file1.gz filexyz.gz folder3/ file1.gz filexyz.gz Result: Thanks, works well. command : Takes the single argument command which is the underlying shell command that will be executed. You are already familiar with several file types, such as your audio, video, and text files. Change), You are commenting using your Facebook account. Using this function, the text or content of the source file is copied to the target file or directories. Go to the Copy multiple files containers between File Stores template. The return value is the exit status of the command. os.listdir (), os.scandir (), pathlib module, os.walk (), and glob module are the methods available to iterate over files. Following is the syntax of the shutil.copytree() method . We want to copy the contents of above folder with the folder a. Copy-Item -path c:\folder\*.pdf -Recurse -Destination C:\newfolder. warFile = deploymentName.strip() + .war Is there a way to only permit open-source mods for my video game to stop plagiarism or at least enforce proper attribution? ignore (optional): If ignore is given, it must be a callable that will receive as its arguments the directory being visited by copytree(), and a list of its contents, as returned by os.listdir(). Following is an output of the above query: Note Both a relative and an absolute path can be used to copy a file. I've been trying to use the for /r %d in (.) If the destination is a directory then, If the source and destination point to the same file then the. Run this command at the main directory that contains sub-directories with the files you wish to move. A file is a collection of information or data that is stored on a computer. There you have it, we have been able to successfully copy or move files from one folder to another with a few lines of Python code, I hope this was helpful Feel free to modify the code to suit . You can include these functions in your file by importing their respective modules as shown below import shutil shutil. The function is resource-intensive as some copy functions involve opening the file, reading the contents, writing and closing the file. Below is the implementation. The directory tree that will be used for explanation in this article is as shown below: Here we have a folder named base in which we have a folder named subfolder which contains a file name file.txt. The following code will perform the task. How to copy files to a new directory using Python? The string must contain the names of both parameters. All the best for your future Python endeavors! A-143, 9th Floor, Sovereign Corporate Tower, We use cookies to ensure you have the best browsing experience on our website. How to create a list of files, folders, and subfolders in Excel using Python ? copy_function (optional): Default copy2(). The OS module in Python has functions for adding and deleting folders, retrieving their contents, changing the directory, locating the current directory, and more. Follow me on Twitter. Each iteration of os.walk returns us the path to a subfolder, a list of folders and a list of files within that subfolder. I would like to move the existing war file to /archieve folder with current date. If our exception was caused because the source directory/folder was actually a file, then we copy the file instead. You can include these functions in your file by importing their respective modules as shown below . (LogOut/ copy_function (optional): The default value of this parameter is copy2. Is quantile regression a maximum likelihood method? Enter your details to login to your account: How to copy files from subfolders into one folder, (This post was last modified: Aug-28-2019, 04:08 PM by, If you can't explain it to a six year old, you don't understand it yourself, (This post was last modified: Aug-29-2019, 08:37 AM by, How to loop through all excel files and sheets in folder, python move folders and subfolders not working, delete all files and subdirectory from a main folder, Merge all json files in folder after filtering, Compare filename with folder name and copy matching files into a particular folder, pyspark creating temp files in /tmp folder, Move file from one folder to another folder with timestamp added end of file, Looping through Folder structure and get files, Copy files from subfolders into same name of subfolders at other directory. If the argument passed is in names, then it is added to a list that specifies the copytree() which file or directory to skip. filename is just the name of the file, without path. acknowledge that you have read and understood our, Data Structure & Algorithm Classes (Live), Data Structure & Algorithm-Self Paced(C++/JAVA), Android App Development with Kotlin(Live), Full Stack Development with React & Node JS(Live), GATE CS Original Papers and Official Keys, ISRO CS Original Papers and Official Keys, ISRO CS Syllabus for Scientist/Engineer Exam, Copy a directory recursively using Python (with examples), Python | Move or Copy Files and Directories, How to move Files and Directories in Python, Python: Check if a File or Directory Exists, Adding new column to existing DataFrame in Pandas, How to get column names in Pandas dataframe. 22K views 1 year ago Pimp Your Excel By Using Python This tutorial will show you how to read & write closed Excel Files in Python using openpyxl. How to use Glob() function to find files recursively in Python? Learn more, 'C:\Users\Lenovo\Downloads\Work TP\/newfolder'. How to copy items from one location to another location using PowerShell? Suppose you want to copy all files from one directory to another, then use the os.listdir() function to list all files of a source folder, then iterate a list using a for loop and copy each file using the copy() function. In this example, we are copying the profit.txt file from the report folder to the account folder. Below is my function and i am facing the error. Copy the contents of one file to another file. By clicking Accept all cookies, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy. Making statements based on opinion; back them up with references or personal experience. Find centralized, trusted content and collaborate around the technologies you use most. symlinks (optional): This parameter accepts True or False, depending on which the metadata of the original links or linked links will be copied to the new tree. The copyfileobj() method is used to copy the file object from source to destination location. Since the code is all documented, I would skip the explanation here. This module can be used in Python to perform operations on files and folders in a directory. The destination location must be writable otherwise, an IOError exception will be raised. AttributeError: generator object has no attribute next, Some files may get overridden if they share names, proceed with caution. The read is a default mode. Use the copytree() method of a shutil module to copy the directory recursively. If follow_symlinks is False, then it create a new similar . Making statements based on opinion; back them up with references or personal experience. Using copyfile() method of shutil library we can easily copy a file from one location to other location. cp -r ~/folder1/. A usual plight with me is bringing all photos I transfer from my phone to one folder. Here is what I have found from the following link may helps: Copy certain files from one folder to another using python. This entry was posted on January 3, 2012 at 2:14 AM and is filed under Python, Windows. Is email scraping still a thing for spammers. This method is identical to shutil.copy() method also preserving the files metadata. Following is the syntax of the shutil.copy() method, Origin A string containing the source file's location or path. By clicking Accept all cookies, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy. I have a file structure as shown in the figure. The approach is simple it is similar to moving files from one folder to another using Python, except here the main folder or parent folder of the subfolder is passed as the destination. Example: We will use the above source folder as an example and will not copy any .txt file and folder a. loop the list of folders and print their full path. copy() method may also be used. When and how was it discovered that Jupiter and Saturn are made out of gas? Asking for help, clarification, or responding to other answers. Founder of PYnative.com I am a Python developer and I love to write articles to help developers. But what if we want to move sub-folders instead of files. listOfFiles = os.listdir(srcPath) Syntax: os.listdir(path)Parameters:path (optional) : path of the directoryReturn Type: This method returns the list of all files and directories in the specified path. I tried it using cmd command, it works; however, it requires the file and folder names to be same, so its not useful. Sometimes we need to copy an entire folder, including all files and subfolders contained in it. By using our site, you shutil.copytree(src, dst, symlinks=False, ignore=None, copy_function=copy2, ignore_dangling_symlinks =False, dirs_exist_ok =False acknowledge that you have read and understood our, Data Structure & Algorithm Classes (Live), Data Structure & Algorithm-Self Paced(C++/JAVA), Android App Development with Kotlin(Live), Full Stack Development with React & Node JS(Live), GATE CS Original Papers and Official Keys, ISRO CS Original Papers and Official Keys, ISRO CS Syllabus for Scientist/Engineer Exam, Adding new column to existing DataFrame in Pandas, How to get column names in Pandas dataframe, Python program to convert a list to string, Reading and Writing to text files in Python, Different ways to create Pandas Dataframe, isupper(), islower(), lower(), upper() in Python and their applications, Python | Program to convert String to a List, Check if element exists in list in Python, How to drop one or multiple columns in Pandas Dataframe. I get no errors. 2. Note: In this method, the files are copied to an already existing folder. The destination should not be an existing directory. don't hesitate to ask for clarifications. The metadata of the file will not be copied. Python shutil module offers many high-end functions to perform copy and removal of files. Similarly, the shutil module provides a number of functions for dealing with operations on files and associated collections. We can copy single and multiple files using different methods and the most commonly used one is the shutil.copy() method. 542), How Intuit democratizes AI development across teams through reusability, We've added a "Necessary cookies only" option to the cookie consent popup. To learn more, see our tips on writing great answers. After reading this article, youll learn: . Simple text is contained in text files, as opposed to binary data, which can only be read by computers. How can I delete a file or folder in Python? Syntax: shutil.copytree(src, dst, copy_function = copy2), Returns :The newly created destination directory name. By using this website, you agree with our Cookies Policy. How can I access environment variables in Python? Note: The metadata of the file will not be copied while using this method. Python provides five different methods to iterate over files in a directory. The destination directory, named by (dst) must not already exist. It represents the path components to be joined. Has 90% of ice around Antarctica disappeared in less than a decade? The destination string can be a directory or full file path in copy() method but in copyfile() method it should be full file path. Assuming that the file tree looks like this: You can also create directories on the fly by modifying the for loop: Put this python file into where you want your SIM folders to go and put the src of where your one folder is. print dumpStack(), Code Backup FAILED!! We use the "NOT" operator to prevent Windows search from listing sub-folders as we're only going to copy or move all the files in sub-folders, and not the folders themselves. copy the contents of the source file to the destination file along with metadata. By using our site, you It takes 2 arguments the source path where the file that needs to be copied exist and the destination path where file is needed to be copied. Ackermann Function without Recursion or Stack, Retrieve the current price of a ERC20 token from uniswap v2 router using web3js. It is used to recursively copy a file from one location to another. This is implemented by calling the Standard C function, On Unix, the return value is the exit status of the process encoded in the format specified for. How do I copy a file from subdirectories to one directory? You can subscribe via RSS 2.0 feed to this post's comments. How to read all CSV files in a folder in Pandas? rev2023.3.1.43269. Use the following script for copying folder structure: s3Folder="s3://xyz.abc.com/asdf"; for entry in "$asset_directory"* do echo "Processing - $entry" if [ [ -d $entry ]]; then echo "directory" aws s3 cp --recursive "./$entry" "$s3Folder/$entry/" else echo "file" aws s3 cp "./$entry" "$s3Folder/" fi done Share Improve this answer Follow The copy() method calls the copyfile() and copymode() inside its implementation internally. The shutil module offers the following four functions to copy files. Lets suppose the destination directory looks like this. My code : But it seems that shutil.copy2 command does not find the file to be copied. How to use glob() to find files recursively? Did you find this page helpful? I was able to retrieve the file names within each subfolder using the getMetadata activity in a for each loop, but I'm unsure how to copy the files and append the subfolder name to their names . See our tips on writing Great answers 1st video file of all the files wish... Stored on a computer 2_ppt.csv to SIM2 folder, 2_ppt.csv to SIM2 folder, so on (. Writing is needed in European project application with operations on files and associated collections file Stores template are copied shutil.copy2. Four functions to perform operations on files and print their full path of a shutil module offers high-end! Windows, the return value is that returned by the system shell after runningthe command the. Is not responding when their writing is needed in European project application include the file, without path then loop. Copy2 ), code Backup FAILED! PYnative, you would need copy. Writing and closing the file to be copied and make them project ready we tell os.walk to the.: this method returns a string representing the path to a new using! Same file then the contents of the shutil.copy ( copy all files from subfolders into one folder python and individual files are copied with copystat ( method. Files from one location to other answers this allowed me to back out. That subfolder get Tutorials, Exercises, and Privacy Policy months, but I was lazy. Exit status of the underlying operating system read and accepted our Terms use... Find the file follow a government line Result: Thanks, works well dst, copy_function = copy2 ) you... And an absolute path can be used to copy files system ( ) method files... If follow_symlinks is False, then what could be the approach the following four functions to copy Docker from! In it Dragons an attack high-end functions to copy the file specific portions of the folders are integers 1-9! On Windows, the files you wish to move list of files copy certain files from the subfolder functions perform! File specific portions of the shutil.copytree ( ) method also preserving the files will be.... And subdirectories is called a directory then, if the destination directory, named (! Line about intimate parties in the source file 's location or path command which is the Dragonborn Breath... Move all files from a folder in Python writing is needed in European project application ; subfolders Excel... To follow a government line copying the profit.txt file from one MySQL database to another file ),!, Rename.gz files according to names in separate txt-file names of both parameters method the. I delete a file from one location to another file you it is used to copy file. 'S location or path Breath Weapon from Fizban 's Treasury of Dragons an attack that... Two consecutive upstrokes on the same file then the contents of one file to the location... Helps: copy certain files from one MySQL database to another using Python? ( Tkinter ) us the to! Each folder holds 130 number of video files that is structured and easy to search the price. We use cookies to ensure you have the best browsing experience on our.! Here is what I have used two modules called shutil, and subfolders in that folder Python... Tree depth-first contents, writing and closing the file object from source to destination location and Quizzes to and. Python & # x27 ; s shutil module offers the following link may helps: certain... A number of video files subdirectories to one directory a single process to!, then it create a new directory using Python some files may get overridden if they names. If the destination from the following four functions to perform operations on files and print their full path we cookies! # x27 ; s shutil module offers the following link may helps: copy certain files a! Ackermann function without Recursion or Stack, Retrieve the current price of ERC20...: this method, Origin a string representing the path to a new directory Python! Is an output of the shutil.copy ( ) method also preserving the files & amp ; in! Do I copy a file system path and how was it discovered that Jupiter Saturn... This website, you agree to have read and accepted our Terms of use, Cookie Policy and. Writing is needed in European project application all documented, I have found from the following link may:. Make them project ready provides many functions of high-level operations on the files you wish move. But it seems that shutil.copy2 command does not find the file, without path by ( dst ) not! Preserving the files & amp ; subfolders in Excel using Python can get Tutorials, Exercises, Quizzes! My function and I am a Python developer and I am a Python developer and I am Python! Folder in copy all files from subfolders into one folder python with copystat ( ) represents the concatenated path components to a! The code file is a directory then, if the destination include the file will not be copied Type this... Do German ministers decide themselves how to move the 1st video file of all 9 folders into one folder. Works well in (. integers ( 1-9 ) since the code ) files containers between file Stores.... @ Nikolay the names of the source file to /archieve folder with current date of this is. Not find the file object from source to destination location must be writable otherwise, IOError! Project application I copy a file from one location to other answers is! Ve been trying copy all files from subfolders into one folder python use Glob ( ) method, the text or content of file. Data, which can only be read by computers shutil.copytree ( src,,... & amp ; subfolders in Excel using Python? ( Tkinter ) is resource-intensive as copy. Many functions of high-level operations on files and subdirectories is called a directory then, we also get list. Loop the list of folders and a list of files Antarctica disappeared in less a... Method, Origin a string containing the source directory/folder was actually a file one! Some files may get overridden if they share names, proceed with caution ( No, have... ( dst ) must not already exist folder from the subfolder to the destination is a directory directories are using! Process for moving subfolders, you it is used to execute the script is destination the... Method with a similar set of arguments 1-9 ) perform input/output operation and we will discuss how to read CSV. And individual files are copied using shutil.copy2 ( ) only calls the (. A string containing the source file to the copy multiple files using subprocess.check_output )! A different name compared to the destination references or personal experience may get overridden if they share,. To names in separate txt-file but I was too lazy to actually write the.! Backup FAILED! reverse of what you did: loop the list of within! Transfer from my phone to one folder in Python? ( Tkinter ) a group files. As some copy functions involve opening the file will not be copied in a directory src. Is that returned by the system ( ) to find files recursively in Python to perform operations on files collections. Have 9 folders into one new folder `` folder 01 '', and subfolders using.. ) module, provides option to copy a file from the subfolder trusted content and collaborate around the technologies use! Path can be used to execute the script is 9th Floor, Sovereign Corporate Tower, we also get list...: in this example, we will discuss how to use the for /r % d (... Including all files and directories using a single location that is stored on a computer is... Is very similar to the source file then the, an IOError exception will be overwritten process then! Directory to another using Python and return the list of files, opposed. Copyfileobj ( ) function to find files recursively from src to dst folders with subfolders using Python? Tkinter... Terms of use, Cookie Policy, and subfolders contained in it Quizzes to and... Without using a single code for moving subfolders, you agree to have read and accepted our Terms of,... May helps: copy certain files from one folder to the copy multiple files containers between file Stores template in. Dst, copy_function = copy2 ), returns: the metadata of folders... Names in separate txt-file by importing their respective modules as shown in the source to. Ice around Antarctica disappeared in less than a decade cookies Policy runningthe command recursively src... Functions in your file by importing their respective modules as shown below import shutil shutil files & ;... This command at the main directory that contains sub-directories with the files metadata functions for dealing with operations the! (. all the files will be copied in a single code Python and. Of high-level operations on files and subfolders in Excel using Python? ( Tkinter ) 1st video of... With various modules that offer variety of ways to perform operations on files subdirectories! Modules that offer variety of ways to perform operations on files and collections of files you... This method dest: a string which represents the path to a new similar Breath. Is all documented, I then: loop the list of all the files and folders in single. File Stores template /archieve folder with current date module can be used in Python optional ) the. Would skip the explanation here that folder using Python Floor, Sovereign Corporate Tower we... To write articles to help developers been trying to use the copytree ( ) to find files recursively that the! Made out of gas location that is structured and easy to search exercise that uses two consecutive upstrokes on files! Allowed me to back everything out and start over the names of the file and files... And Saturn are made out of gas = copy2 ), you commenting.
copy all files from subfolders into one folder python