I'm trying create folder:
import os
mypath = (r'C:\my_folder')
if not os.path.isdir(mypath):
os.makedirs(mypath)
I've got error from windows or if this way mypath = (r'C:\ProgramData\my_folder')
I got this error:
mkdir(name, mode)
PermissionError: [WinError 5] Access is denied: 'C:\\ProgramData\\my_folder'
so as script does not have permissions to write, now with help from previous post here
I must use this rule:
this way:
import os
mypath = os.path.join(os.getenv('programdata'), 'my_folder)
if not os.path.isdir(mypath):
os.makedirs(mypath)
and I got folder here:
C:\ProgramData\my_folder
Works, but new problem, for example as it was before: mypath = (r'D:\my_folder\)
this way I have folder and when I start program first time, this creates textdoc.txt inside, works perfect, but if I go this way mypath = os.path.join(os.getenv('programdata'), 'my_folder)
If with first one I have one textdoc.txt, now I have two: textdoc without extension and second textdoc.txt. Well it's ok if just copy, but it completely spoiled a data work, specific lines are recorded in one file other parameters in textdoc without extension. I checked several times all access to the database, no errors in the code and it does not happens with local working path mypath = (r'D:\my_folder')
EDIT:
I'm just missed something in my code, not associated with the method itself
so working one:
Same answer that is given here: PermissionError: [WinError 5]
import os
mypath = os.path.join(os.getenv('programdata'), 'my_folder')
if not os.path.isdir(mypath):
os.makedirs(mypath)
and path for document:
C:\ProgramData\my_folder\document.txt