Python Forum
deleting files in program files directory
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
deleting files in program files directory
#2
Windows doesn't grant administrative privileges to scripts by default.
If run cmd as Administrator the run python script it will work.

There are packages that deal with this eg pyuac
Teset work.
import os, time
import pyuac

file_path = r'C:\Program Files (x86)\game\pong – Kopi.exe'
if not pyuac.isUserAdmin():
    pyuac.runAsAdmin()

os.remove(file_path)
Do not do this when use a file path,because of escape characters.
# No
'C:\Program Files (x86)\Microsoft'

# Ok
r'C:\Program Files (x86)\Microsoft'
'C:/Program Files (x86)/Microsoft'
Reply


Messages In This Thread
RE: deleting files in program files directory - by snippsat - Aug-17-2024, 07:44 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Correct/proper way to create save files snakes 0 438 Mar-11-2025, 06:58 PM
Last Post: snakes
  Merge htm files with shutil library (TypeError: 'module' object is not callable) Melcu54 7 3,299 Mar-09-2025, 04:25 PM
Last Post: Pedroski55
  how to download large files faster? kucingkembar 3 776 Feb-20-2025, 06:57 PM
Last Post: snippsat
  Inserting Python Buttons into KV Files edand19941 3 473 Feb-19-2025, 07:44 PM
Last Post: buran
Question [SOLVED] Right way to open files with different encodings? Winfried 3 3,965 Jan-18-2025, 02:19 PM
Last Post: Winfried
  Applications config files / Best practices aecordoba 2 1,851 Oct-23-2024, 12:56 PM
Last Post: aecordoba
  Compare 2 files for duplicates and save the differences cubangt 2 926 Sep-12-2024, 03:55 PM
Last Post: cubangt
  Convert Xls files into Csv in on premises sharpoint Andrew_andy9642 3 983 Aug-30-2024, 06:41 PM
Last Post: deanhystad
  I'm trying to merge 2 .csv files with no joy! Sick_Stigma 3 914 Aug-03-2024, 03:20 PM
Last Post: mariadsouza362
  Class test : good way to split methods into several files paul18fr 5 3,534 Jul-17-2024, 11:12 AM
Last Post: felixandrea

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020