0

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

PermissionError: [WinError 5]

I must use this rule:

https://blogs.msdn.microsoft.com/patricka/2010/03/18/where-should-i-store-my-data-and-configuration-files-if-i-target-multiple-os-versions/

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

Community
  • 1
  • 1
  • The code you've posted doesn't create a textdoc or do anything with it. I suspect the problem is in your code after the directories are created. – Steve May 01 '16 at 05:39
  • yes text file created after, but as I've said it does not happens if I have location outside system files for example with mypath = (r'D:\my_folder') –  May 01 '16 at 19:28

0 Answers0