Answer the question
In order to leave comments, you need to log in
Can't copy file via shutil. [Errno 13] Permission denied. What to do?
You need to use python to copy the file (folder with files) from the directory C:\Users\User\Documents to the directory C:\Users\User\AppData\files\results\Crossout . The question is how to do it with python if shutil writes: PermissionError: [Errno 13] Permission denied: 'C:\\\\Users\\\\User\\\\Documents\\\\My Games\\\\ Crossout? Maybe you can use some other libraries, or am I mistaken somewhere?
The code:
import getpass
import os
import shutil
user = getpass.getuser()
Path = rf"C:\\Users\\{user}\\AppData\\files\\results"
Crossout = rf'C:\\Users\\{user}\\Documents\\My Games\\Crossout'
if (os.path.exists(Crossout)) == True:
if not os.path.exists(Path + r"\\Crossout"):
os.mkdir(Path + r"\\Crossout")
shutil.copyfile(Crossout, Path + r"\\Crossout\\Crossout Passwords", follow_symlinks=True)
Answer the question
In order to leave comments, you need to log in
PermissionError: [Errno 13] Permission denied: there seems to be a permissions issue here
os.mkdir(path, mode=0o777)
First, get familiar with the pathlib standard library for working with paths, it will be much easier. In particular, look towards Path.expanduser() .
Second, understand the exist_ok parameter in the directory creation and copy functions so you don't have to write if's to create directories.
Third, copyfile() only works on files, as the name suggests. She does not understand what to do with the directory. The behavior you expect is provided by the shutil.copytree() function .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question