Hand off the work - subprocess
Step 1
You don’t know on which OS this script will run eventually. So you should first determine if you are running on an UNIX System or on Windows.1
Save the result in an efficient way in a variable2
Step 2
List all existing files in your current directory using the subprocess.3,4
Run your script.
Step 3
Since your terminal got a bit messy from the output of the last subprocess command it is time to clear the screen after five seconds.5,6
-
To do this you should have a look at the
platformmodule and itssystem()method. ↩ -
A
Bool-Value would be more efficient than the returned String. ↩ -
Here you have to decide which command you have to call
ls -lhafor UNIXdirfor Windows. ↩ -
Remember you have do pass a list with every argument in a single string, if there are whitespaces in your command. Use
subprocess.run()here. ↩ -
To wait a certain amount of time use
time.sleep(in_seconds)from thetimemodule. ↩ -
Here again: UNIX command is
clear, Windows command iscls. ↩