2

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?

8
  • Those things are called environment variables. (Also, that's not DOS.) Commented Jul 8, 2018 at 21:39
  • 1
    @melpomene probably os.path.expandvars() is a better fit than just accessing environment variables. And I am sure there is some subtlety but how is this not a DOS (.bat) script? (I know recents is a windows things but the script itself?). Commented Jul 8, 2018 at 21:49
  • Not really related to the asked coding problem, but it might be easier to use new system user accounts or guest accounts in these scenarios... Commented Jul 8, 2018 at 21:53
  • I couldn't find a perfect dup, but I added two that show how to use expandvars to solve similar problems. If someone knows of a better one that could replace all three of these, that would be great. Or, to the OP: Do those dups together tell you everything you need to solve this, or is it still unclear? Commented Jul 8, 2018 at 21:54
  • I added another one that is also close but based on UNIX env variables. Commented Jul 8, 2018 at 21:55

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.