Reputation: 575
import os
test = os.path.exists("c:/conf.txt")
if test == False:
with open("c:/conf.txt", "w") as Inc:
Inc.write("0")
Inc.close()
quit()
if test == True:
f = open("c:/conf.txt", 'r')
b = int(f.readline())
b +=1
with open("c:/conf.txt", 'w') as writeinc:
writeinc.write(str(b))
writeinc.close()
using open(c:/conf.txt)
doesn't work (also tried c:\.)
I get the following error message:
IOError: [Errno 22] invalid mode ('w') or filename: 'c:/conf.txt'
Is there a way to access a different directory using open()
according to absolute path rather than relative?
Upvotes: 0
Views: 95
Reputation: 59681
Sounds to me like you don't have permission to write to the root path of your drive. In Windows 7 and 8, you cannot create files in the root directory:
In Windows 7 or 8 (may be Vista), users (even administrators) are not allowed to create files in the C drive root directory, otherwise, an error message like “A required privilege is not held by the client” or “access is denied” will be prompted.
The article goes on how to modify the registry if you want to get around this restriction.
- Press keys “Windows Key + R”, type regedit
- Locate HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA
- Update the EnableLUA value to 0 (turn if off)
- Restart Windows.
Upvotes: 1