@Helvetosaur wrote:
Somewhat OT here, but I was wondering if anyone knows how to rename a file in a restricted directory via Python script. The catch is that the file is in a subdirectory of C:\Program Files and to change anything in there you need to have administrator rights. Even logged in as administrator, when doing it manually, UAC still asks for confirmation. And in the following script it just fails…
prefix='X' orig_fname='blabla.xyz' new_fname=prefix+orig_fname direc='C:\Program Files\BlaBlaBla' orig_fpathname=os.path.join(direc,'orig_fname') new_fpathname=os.path.join(direc,'new_fname') if os.path.isfile(orig_fpathname): os.rename(orig_fpathname, new_fpathname) #should rename the file to 'Xblabla.xyz'
But this fails with a message “Windows error”. I assume that means “permission denied”…
I can’t put this file anywhere else on the computer either, it only works in that directory. I am just trying to deactivate the automatic loading by keeping the app which looks for it from finding the correct filename. But I also need to restore it later.
If anyone has any ideas…
Posts: 1
Participants: 1