Questions tagged [shutil]

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

Filter by
Sorted by
Tagged with
0 votes
0 answers
35 views

Zipping all subfolders in a folder - Python [duplicate]

I made a script to zip all subfolders in a specific folder (I want one zip per subfolder) but it seems that shutil doesn't recognize " - " (space/hyphen/space) : import os import shutil path ...
Maxence MELIN's user avatar
0 votes
0 answers
20 views

The results from python's shutils.disk_usage() on an optical drive differs from the properties reported by windows on the same drive

I am calling the disk_usage() method on python's shutils for an optical drive on windows: stats = shutil.disk_usage('F:') This returns: Total: 2976847872 Used: 2976847872 Free: 0 When I select the ...
Drew S.'s user avatar
  • 25
0 votes
1 answer
40 views

Moving files with subfolders based on dictionary Python

I am trying to figure out a faster way to copy and move pdf files that are in multiple subfolders. The current code I am using will find the file if it is anywhere in the main folder directory but ...
NerdBurgler's user avatar
0 votes
1 answer
86 views

How to copy a directory structure along with specific file extensions?

I've been trying for days now and searched online for solutions and I only found problems similar to mine which didn't help me. The best I managed so far is to copy the entire structure with all files ...
Strider90's user avatar
0 votes
0 answers
21 views

Access the share folder using Python

# Caminho para o arquivo de origem caminho_origem = 'C:\\TesteScript/' # Substitua pelo caminho real do arquivo de origem # Caminho para a pasta de destino compartilhada na rede caminho_destino = r'\...
Rafael Ferraria's user avatar
0 votes
0 answers
41 views

Should I use shutil.copy() inside a with block

So every newbie to Python learns that it is a good thing to put file operations such as reading from and writing to a file inside a with block such as with open(path, 'w') as f: f.write(s) But is ...
O-leChuck's user avatar
0 votes
0 answers
24 views

Moving files to the respectful folders based on their extensions

I need to move the files with the extensions, which are not listed in dict, to 'Unknown_folder'. It works, however when I add 'else:', all files (even with the extensions listed in the dict) will be ...
Andrii Kovalchuk's user avatar
0 votes
1 answer
26 views

Append processed data to a csv file and keep reord of last procssed row

I have 4000 csv files in a folder in windows 10, each files has around 500 rows,where i read text column and few identity column, each file got processed in a loop and saved. Because of system ...
Remrem's user avatar
  • 27
0 votes
0 answers
8 views

How to list files in directory based on order in column

I have files listed in a non-alphabetical order in a column in my csv. I want to list the files in the directory according to the order of the csv. I made a .txt file of all the file names (plus ...
sprc's user avatar
  • 31
-1 votes
1 answer
45 views

Is there a way to iterate over each file in a folder before copy in Python?

Each picture with .png extn in a X folder has to be copied, compare to values in excel and paste to different folder Y based on a condition. Here are my 2 problems, My script is copying all the ...
Dakshin Parivallal's user avatar
0 votes
2 answers
58 views

How to move files in to new directory based on column values (ID, number)

I have a csv file with filenames in the file_name column and site numbers in the site_number column. I have a directory with files that match the filenames in the file_name column plus and extensions ...
sprc's user avatar
  • 31
0 votes
0 answers
22 views

check updates on each subfolder of subfolders dcmp python

I am trying to build a back-up script in order to back-up all my pc to an external ssd(lost all my data 3 times by now). It works great for the files and main folders but until now I am not able to ...
Catalin's user avatar
  • 292
0 votes
0 answers
28 views

Cancel a stalled file copy in Python in Linux

Is there a way of cancelling a file copy if, after a while, the copy is stalled and there is no progress? I'm using shut.copy to copy files from one directory to another. The problem is that there are ...
asuka's user avatar
  • 2,259
-1 votes
1 answer
62 views

Permission Denied for shutil.copy

Why is it, that when I run this python code (even as administrator, and yes, I've checked the permissions beforehand), that it keeps telling me "Permission denied"? Could somebody please ...
user22538038's user avatar
0 votes
1 answer
31 views

Unexpected behaviour when re-organising directory (python, shutil)

I have a function that reorganises a directory of locally saved data, but its behaving in an unexpected way. There are 3 folders, current, previous and tma (two months ago) and with the function below ...
nos codemos's user avatar
0 votes
2 answers
43 views

Pulling pictures from folder based on excel list

I am currently just playing around and getting to know python as a whole. My current "Task" is to pull pictures from an already existing folder on my HDD based on a list of picture names ...
roglen's user avatar
  • 1
0 votes
1 answer
29 views

File sorting program makes nested directories if executed again

When the code is run for the first time everything works perfectly but when i execute it a second time the already present directories are nested and the code stops after the error that it cannot put ...
divyansh1611's user avatar
1 vote
1 answer
81 views

FileNotFound error when renaming files using shutil.move in Python

I'm in chapter 10 of Automate the Boring Stuff, and one of its activities suggests renaming files in order when one is missing (e.g., Spam001.txt, Spam002.txt, Spam004.txt, ...). When testing the code ...
Donj's user avatar
  • 27
0 votes
1 answer
84 views

Openpyxl File Corruption/Pandas to Existing Excel Table

Longtime lurker, first time poster. This forum is an amazing resource but I'm officially stumped. I have a large and complex xlsm file that I need to manipulate using openpyxl but my final file ends ...
loren_neosporin's user avatar
0 votes
0 answers
35 views

Python shutil.unpack_archive exit with Errno 22, how could files left to be unpacked?

When do unpack with shutil, Errno 22 pop up. Some files cannot unpack is OK, but how could files left to be unpacked? Or how could do unpack with errors ignored? try : shutil.unpack_archive(file, ...
Fukai's user avatar
  • 381
0 votes
1 answer
51 views

How to return a value from onerror callback in shutil.rmtree

Working with rmtree from shutil module, I made some tests to delete some directories and their content, knowing that rmtree takes a callback function on onerror argument, I created a function to keep ...
DarKing's user avatar
  • 25
0 votes
3 answers
36 views

How to scan directory and then move files based on conditions?

Ideally, it'd scan through the downloads folder, find the files whose extensions are '.png' or '.jpg', then move those files to the pictures folder. Here is my code: import os import shutil import ...
Zane Ritchie's user avatar
0 votes
2 answers
78 views

How to move files to and from folders using shutil and os in python?

So, I'm looking to move some images from my downloads folder to my pictures folder (Windows 11), but I am continually being met with errors. Here is my code: import shutil import os source = r"...
Zane Ritchie's user avatar
-1 votes
1 answer
57 views

Copy directories in python

When I want to copy the folders from a specific folder to another folder, I come up with error.Could you please explain to me why it has happened? import shutil os.chdir('/content/gdrive/...
fatemeh khoshhal's user avatar
0 votes
1 answer
75 views

How can I delete hidden folders with Python?

I need to delete .git hidden folder with python for a project. I have a function to do that but it does not work. :( def delete_hidden_files(folder_path): try: # Gets the list of files in ...
3xoticGamerrrYT's user avatar
0 votes
0 answers
61 views

How can I get my Flask app to automatically backup at a set time?

I have a Flask app that already has the ability to be backed up locally to a .zip file using shutil.make_archive() which works when manually initiated via a menu from the front-end website. However, ...
p_sky's user avatar
  • 1
-1 votes
1 answer
51 views

Is there a way to use shutil to copy a file when you don’t know the whole file name?

I am trying to use shutil.copy to copy files that I don’t know the whole name for. The names typically are 11_11_2023_functional. The date changes each for each file but they are in separate folders. ...
Will V's user avatar
  • 1
0 votes
0 answers
77 views

How should I create a shortcut using Python and add it to the startup folder of the computer?

I am trying to create a Python code that I will later convert to a Windows executable (.exe) using PyInstaller. The code is supposed to display a message in a window, and add a Windows shortcut (.lnk) ...
redbackspider's user avatar
0 votes
2 answers
53 views

I can't find my .txt files after a code execution on Python IDLE

I'm learning how to use Python and I decided to write a code off my head based on what I had learnt previously. I opened python IDLE shell and wrote this code to move txt files into a folder: import ...
Tolu A-Daniels's user avatar
0 votes
0 answers
10 views

How do different filesystems handle reads concurrent with read-write/update access?

Concurrent Read/Write For any given NAS architecture, if user B wants to copy the file from the NAS device and User B (using a different machine to access the NAS): Is already modifying the file when ...
Isaacnfairplay's user avatar
0 votes
1 answer
42 views

Move content of a folder using shutil

I am trying to move the content of a folder to another in Python using shtutil but it's not working as I expected. dest_dir = shutil.move(str(source_directory), str(dest_dir)) return dest_dir Let's ...
Fábio Pires's user avatar
-1 votes
1 answer
63 views

Getting file size of data when using requests.get and shutil copy object

with requests.get(….) as r: With open(filepath,’wb’) r.raw.decode_content = True shutil.copyfileobj(r.raw,f) Initially we used to take file size as len(chunk)
G Naik's user avatar
  • 9
0 votes
0 answers
17 views

Extract name of main subfolder, create new subfolder, and move files from source to destination

I'm fairly new to python but I'm trying to write a code that essentially looks at all the folders in my source path, extract the names of the folders in the source and create new folders with a ...
RyanE's user avatar
  • 1
-2 votes
3 answers
124 views

Move files with a condition in Python

I need to move files from one folder to another based on a given condition. The condition is that if a certain file has more than or equal to 100 rows (for example), it will be moved to another folder....
solo1111's user avatar
0 votes
2 answers
146 views

save images to folder from DeepFace.find()

I have this code: from deepface import DeepFace image1 = "test.jpeg" DeepFace.find(img_path = image1, db_path = "faces", enforce_detection = ...
eitan's user avatar
  • 19
0 votes
0 answers
56 views

shutil copyfile() throws Errno2: No such file or directory, by the destination file

So,I thought at first I had made a mistake in the Path Name for the file's destination, but I went to the folder through the terminal, copied the path to my code, permissions are set to 777, I just ...
Frédéric Pepin's user avatar
2 votes
1 answer
92 views

Copying a file into multiple folders using Python

I have a file Test.py. I am pasting this file into 2 different folders as shown below but I also want to change File=1 based on the folder it was pasted. For example, it is pasting Test.py into ...
KeplerNick123's user avatar
0 votes
0 answers
14 views

Fetching data using url which is of db and which had multiples folders and files in it and then saving it to zipped python file

Fetching huge data around 60 Gb data using requests module with url which is of db and which has multiples folders and files in it and then saving it to zipped python file. Right now I am testing with ...
G Naik's user avatar
  • 9
1 vote
0 answers
39 views

Fetching data from a source and saving it to zipped python file

I am trying to fetch huge data around 50GB from a database source and then save it to a zipped python file . I tried with less data of 5 Gb for testing using 1.requests module and then dividing the ...
G Naik's user avatar
  • 9
0 votes
1 answer
163 views

How can I extract and rename specific files from daily compressed zip folders using Python?

Let me preface this by I have never worked with python before but have spent the past several days researching and watching videos. Although I've found solutions that helps with components of this, I'...
lunaliz's user avatar
  • 25
0 votes
0 answers
74 views

Failure to run shutil.copytree when source folder on network drive

Half of our developers are running into an issue using shutil.copytree. I think this is a Python question, but it could likely be a networking/hardware question as well, so I am providing as much ...
Erwan Leroy's user avatar
0 votes
2 answers
190 views

How can I overwrite a file in a different folder using shutil.copy() and os.rename() in Python?

I have a script which outputs an excel file '.xlsx' containing various data. It generates a file with the date in the name in one folder, and then generates a copy, using shutil.copy(), in a separate ...
Tom Owen's user avatar
0 votes
1 answer
141 views

os.makedirs is creating a new folder with file name

I'm trying to copy all folders and files from one path to another if a file doesn't contain a substring called "obsolete". Here is my code: import os import shutil rootdir = "C:/Old&...
user026's user avatar
  • 640
0 votes
0 answers
33 views

FileNotFoundError when using shutil in python

Hello i worte the folloring funktion, it shouid move files from one folder to a nother one. This works most off the time but sometimes it throws this exception. Maby every 100 run. def __move(self): ...
Gustje04's user avatar
0 votes
1 answer
59 views

Will this be sufficient for copying a complete directory to another directory and monitoring the output?

I am trying to copy over a terabyte of data from one network location to another using the python script below. import shutil import os import logging # logging copy data def _logpath(path, names): ...
Andrew Feenan's user avatar
-1 votes
4 answers
115 views

How can I copy every n files to a different folder

I have a folder with 20 photos and the names of these photos are respectively image1.png, image2.png, ..., image20.png. I want to copy these photos into four different folders. For example in Folder1 ...
Yiğit Kağan Alpaslan's user avatar
0 votes
0 answers
135 views

How do I make shutil.move perform a direct move instead of copying file then deleting the original?

I have a huge OSMC/kodi media collection and am trying to organize it better. I am using shutil.move to move the files from a drop folder to the proper storage location after the script makes sure ...
Chameleon's user avatar
-1 votes
3 answers
546 views

How do I save multiple Pandas dataframes to different sheets in a single .xlsx, in Databricks?

The following code allows me to save a Pandas dataframe df to a .xlsx file in the Databricks filestore: import shutil final = '/dbfs/FileStore/test.xlsx' temp_file= '/tmp/test.xlsx' df.to_excel(...
Sam Eley's user avatar
-1 votes
1 answer
55 views

cv2.imread() fails to read subsequent images in a loop operation

I have the below code segment which converts a PDF with multiple pages, store the pages as separate PNGs in a directory and then use OpenCV to read all PNGs in a loop. However, cv2.imread() returns ...
wr93_'s user avatar
  • 130
0 votes
0 answers
25 views

How do I store the destination filepath i copied using shutil into a variable

The problem is that I would like to copy the file uploaded to a new folder called 'video store', then the name of the file that has just been copied to 'video store' is stored in a variable to be used ...
Ivan McKenna's user avatar

1
2 3 4 5
24