Wednesday 22 February 2017

accessing certain system-name folders (%appdata%) in Windows with Python

I'm a noob to this site, found lots of answers to other coding challenges in the past.



I'm also a noob to programming in Python. I have some code I wrote in DOS few years ago. Let me explain why:-



when you are using Windows 10 it keeps a log of "files used recently" this can be a big problem when I did a Windows 10 rollout at a big charity, and our HR team needed to borrow a laptop for a meeting, and when I got it back, logging on with the generic log on which was shared, a file was deleted but in frequently used files was something along the lines of "internal investigation into Mr _____.docx" which sounded very confidential.



Anyways, this script I wrote, doesn't disable Windows 10 recently used files, it makes a copy of these files and throws them in a 7zip file. When its finished, it deletes the frequently used list of files, and re-opens with 7zip and puts the files back where they were, so no one knows something sensitive has been used in the meantime.



I did this using part of this script in DOS calling 7zip from command line.




rem *** get rid of the current shortcut list of recently used files ***

del /F /Q %APPDATA%\Microsoft\Windows\Recent\AutomaticDestinations\*

rem *** put back the previously copied set of shortcuts ***

x:\apps\7-zip\7z.exe x x:\internals\scripts\win10recent.7z -o%APPDATA%\Microsoft\Windows\Recent -y


I'm now trying to rewrite this in Python. I'm entirely new to Python, (I'm not an actual programmer by trade) but learned a lot from Googling around to make some portions of the code work so far functional.




Just opening 7zip from within Python I have to do this:-



subprocess.call(['x:\\apps\\7-zip\\7z.exe'])


Here's the bit I am stuck. To call certain generic paths with the % symbols around it, example for %appdata%. I've searched around but I am not sure how I can call this path within Python?



any ideas?

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...