Questions tagged [shutil]

A Python module which contains a number of utility methods for file or directory operations, such as copying, moving, etc.

The Python shutil module offers a number of high-level operations on files and collections of files. In particular, functions are provided which support file copying and removal.

Documentation: https://docs.python.org/3.2/library/shutil.html

1181 questions
-2
votes
1 answer

Copy a non-empty folder in python

How to copy a non-empty folder in Python ? I am want use like unix command " cp -r " Ex.. sourceFolder = /tmp/Folder1/file1.txt destinationFolder = /tmp/Folder2/ after copying sourceFolder is look like " /tmp/Folder2/Folder1/file1.txt " I am trying…
-2
votes
2 answers

How to copy files from folder or subfolder with Python?

I have a Folder with many subfolders that also have subfolder in them and they also have subfolders and so on. I need certain files from that folder to be found by python and copied to a destination folder. I found shutil.copy but this need the…
Erik
  • 49
  • 5
-2
votes
1 answer

Move files to folder made by user input with the same name

I have a directory containing the following: name.xlsx I use the following code to have a user input names for the folder(s) they would like to create in that directory. dirPath = ‘dir_path’ naFold = input(“Enter name: ”) lst = naFold.split(“,…
GooseCake
  • 33
  • 8
-2
votes
2 answers

How to move files based on their names with python?

I have a folder with a lot of tutorial links, so I wanted to create a script that reads the file name and for instance, if the file has in its name the word "VBA" or "Excel" it would create the folder Excel and send to it. The same would happen with…
-2
votes
1 answer

How to copy images from one folder to another using Python?

I have 10 images in the folder(1.jpg, 2.jpg, 3.jpg, ..., 10.jpg) and I want to copy only 5 images(1.jpg, 2.jpg, 4.jpg, 6.jpg, 8.jpg) into another folder. But I am getting this error. ` Traceback (most recent call last): File…
-2
votes
2 answers

How to I move a directory in python using shutil library?

I'm trying to move a file but it won't work. It keeps giving the error "Errno 2: File or directory does not exist". The code is shown below import shutil original = '%userprofile%/Desktop/Test' New =…
SpicySoap
  • 3
  • 3
-2
votes
1 answer

Renaming files in same directory with Python

I have the following code which renames txt files according to a list with 8 elements. I can successfully rename the files if I move them to a different directory first. However, when I want to move the files to the same directory and rename by…
Shaye
  • 179
  • 13
-2
votes
1 answer

Remove folders but the csv files

I have a folder (folder_1) that consists of many different subfolders, these subfolders (subfolder_1, subfolder_2, etc etc) all consist of 1 csv file. I'd like to delete all subfolders, and just keep all csv files. Is there a way to achieve this…
-2
votes
1 answer

Copy file from a folder to another

I want to copy a file from a folder, one directory above the python script being interpreted, to a folder in the same directory the python script lives. This is the folder…
user1584421
  • 3,499
  • 11
  • 46
  • 86
-2
votes
1 answer

Is there a way to set an operation to a boolean, then create an if statement to do something if that operation was done?

So I'm moving a lot of files within folders to the layer above all the folders. Essentially what I need to happen is if a file was removed from a folder (to the layer above), then delete the folder it was removed from. Something like: for file…
-2
votes
1 answer

Unable to download youtube videos from shutil Python

I want to download a YouTube video using Python. I use this code to scrape images and it worked fine. But when i changed this image link to youtube video then it saves the file, but makes an error corrupted mp4 file. Any idea what i am doing…
Abhay Salvi
  • 890
  • 3
  • 15
  • 39
-2
votes
2 answers

Finding a filename with zip in the following folder/ directory and extracting it to a new folder in the same directory?

I have used os.walk() to get the list of files to a DataFrame. Now I want to extract the zip folders from the list of files in the DataFrame. DataFrame file_name base_name extension absolute_path rel_path file_1.pdf file_1 …
Deepak Harish
  • 123
  • 2
  • 7
-2
votes
1 answer

Problem while recursively and selectively copying a folder in python scipt

I want to make a python script that recursively copies from src to dest and and I also want to make some rules like it shoudn't copy .py files or .log files. I have to tried ignore_pattern but using shutil.copyfile . All the files are getting copied…
whoami
  • 1
  • 2
-2
votes
1 answer

Cannot merge various text files with similar names into one file

I have an issue, where I iterate through the folder and would like to merge files containing particular name. I have files like 1a_USR02.txt, 1b_USR02.txt and 1a_USR06, 1b_USR06. However when I use the following code, the final file FINAL_USR02 or…
user9799161
  • 123
  • 2
  • 14
-2
votes
1 answer

how to copy a folder in python

I need a function that lets me copy a folder and what is in the folder into another existing folder. I have tried "shutil.copy", "shutil.copy2" and shutil.copytree" none of these do what I want. I am on python 3.6.2 on windows 10. I am still…
1 2 3
78
79