shutil

permission denied issue when trying to access files in a folder with xlrd or shutil

瘦欲@ 提交于 2020-01-24 13:35:19
问题 Edit: I deleted this but I'm going to undelete because I think it could be useful. And post what was actually happening which I didn't realize at the time. Original Question: I'm trying to open a set of excel files where one is currently open by another user. All of the other files work, but this one I get 'permission denied' errors. Windows gives you the option to "read only" open the file, but I can't seem to find an equivalent in python (xlrd), so I thought I would copy the file to a temp

Can anyone explain this weird behaviour of shutil.rmtree and shutil.copytree?

不想你离开。 提交于 2020-01-13 19:00:25
问题 I'm building a relatively simple application that asks for directories, checks if they're correct, and then removes one of them and recreates it with contents of the other one. I'm encountering this weird behaviour, I'll try to explain: When I've got the destination folder window open, AND it's empty, there's an access denied exception, then I get kicked out of the folder and it gets removed. But then if it's not empty, it works just fine, no exceptions, the destination directory (from what

`shutil.copyfile` Error: Permissions Denied

时间秒杀一切 提交于 2020-01-06 06:10:44
问题 I have worked through a number of other threads on this, but not of their solutions seem to work here, that or I am not understanding properly, and would love your help. I am getting a: IOError: [Errno 13] Permission denied: 'W:\\test\\Temporary Folder 195\\Sub-fold1 This is the general code i started with. summary_file = r'W:/test/SDC Analysis Summary.docm' shutil.copyfile(summary_file, os.getcwd()) I have also varied this a little bit based on other threads, specifically replacing summary

How to Change First Line of File in Python?

删除回忆录丶 提交于 2020-01-06 02:08:11
问题 Why does Python-2.7 on Windows truncate a file? The problem is well known with shutil.copyfile but I don't understand how to avoid it when I'm changing the first line. File size is unknown and could be huge. Reference below but I'd prefer better exception handling with something like the following code: import os import sys import shutil with open(sys.argv[1], 'r+') as src: line = src.readline() with open(sys.argv[1], 'r+') as dst: dst.write = sys.argv[1]+'\n' shutil.copyfileobj(src, dst)

python 2 [Error 32] The process cannot access the file because it is being used by another process

白昼怎懂夜的黑 提交于 2020-01-05 07:19:07
问题 I'm working with python 2 and have read several posts about this error i.e(this post). However, I'm still getting the error. What I do is: I read the files in a directory, if any of the files contains a specific string, I delete the directory. def select_poo(): path = os.walk('/paila_candonga/') texto = 'poo' extension = '.tex' for root, dirs, files in path: for documento in files: if extension in documento: with open(os.path.join(root, documento), 'r') as fin: for lines in fin: if texto in

shutil.rmtree fails on Windows with 'Access is denied' [duplicate]

半腔热情 提交于 2019-12-28 02:26:06
问题 This question already has answers here : Deleting directory in Python (6 answers) Closed 5 months ago . In Python, when running shutil.rmtree over a folder that contains a read-only file, the following exception is printed: File "C:\Python26\lib\shutil.py", line 216, in rmtree rmtree(fullname, ignore_errors, onerror) File "C:\Python26\lib\shutil.py", line 216, in rmtree rmtree(fullname, ignore_errors, onerror) File "C:\Python26\lib\shutil.py", line 216, in rmtree rmtree(fullname, ignore

copy folder, subfolders and files from a path to another path in python via a recursive function

徘徊边缘 提交于 2019-12-24 07:59:35
问题 I want to copy some folders and files from a path to another path. for example, I want to copy the folder(called folder1) which has some other subfolders and some files inside itself to another folder(dst). In my program, at the first, I want to check if there is a folder named folder1 in destination folder and if not, create a folder with folder1 name and then copy the content of folder1 to target. In addition, maybe we have folder1 in the target path, but there are some subfolders of

Python shutil.copy fails on FAT file systems (Ubuntu)

偶尔善良 提交于 2019-12-23 09:34:26
问题 Problem: Using shutil.copy() to copy a file to a FAT16 mounted filesystem in Linux fails (Python 2.7.x). The failure is shutil internal error and failing actually on shutil.chmod, which shutil.copy seems to execute. Shell chmod fails, too, as permissions are not supported in FAT. Questions: Is there any neat way around this? I know I have several options, for example: Use copyfile - not ideal as it requires full path, not just target directory, but doable Execute shell cp to copy files Write

shutil.copytree without files

此生再无相见时 提交于 2019-12-21 03:57:46
问题 I'm trying use shutil.copytree: shutil.copytree(SOURCE_DIR, TARGET_DIR, ignore=None) This copy also files in folder. I need copy only folders without ANY files. How to do it? 回答1: You can do that by providing a "ignore" function def ig_f(dir, files): return [f for f in files if os.path.isfile(os.path.join(dir, f))] shutil.copytree(SRC, DES, ignore=ig_f) Basically, when you call copytree, it will recursively go to each child folder and provide a list of files in that folder to the ignore

using shutil.copyfile I get a Python IOError: [Errno 13] Permission denied:

不打扰是莪最后的温柔 提交于 2019-12-19 16:12:11
问题 I have some python code using shutil.copyfile: import os import shutil src='C:\Documents and Settings\user\Desktop\FilesPy' des='C:\Documents and Settings\user\Desktop\\tryPy\Output' x=os.listdir(src) a=os.path.join(src,x[1]) shutil.copyfile(a,des) print a It gives me an error: IOError: [Errno 13] Permission denied: 'C:\\Documents and Settings\\user\\Desktop\\tryPy\\Output' Why don't I have permission to copy the file? 回答1: From the documentation of shutil.copyfile : Copy the contents (no