简体   繁体   中英

Use python to modify file (workaround for WindowsError 5 Access is denied)

I am trying to augment C:\\program files\\%X%\\%text_file%.txt .

I am admin on my PC and granted full access to all users on this text file (overkill, but its a local PC).

I am trying to use the solution documented here , yet I am still getting WindowsError: [Error 5] Access is denied .

My goal would be to have a script that systematically can go in and modify the text file. My current python code matches that in the link above directly.

Thank you for any guidance!!

Without sample code to demonstrate the usage, I can only presume that you are using "C:\\program files\\%X%\\%text_file%.txt" directly and there are no valid environment variables for "X" and "text_file" for it to replace with.

On Windows, a value wrapped in % is expanded and replaced with an environment variable. For example echo %TEMP% at the Command Prompt (CMD.EXE) will expand out the TEMP environment variable and print out something like C:\\Program Files\\Temp

I hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM