Automating tasks in Python – Running many Python Scripts, running scripts at startup


I started my automation by making a script for cleaning up my C code’s directory. I then thought what would happen if I had more than one scripts for automation? I thought to make a script for running other Python scripts.

import sys
import subprocess

theproc = subprocess.Popen([sys.executable, 
"Deleting extra files.py"])
theproc.communicate()

This simple script can be used to run a script in the current directory. Here sys.executable is for the Python exe present on the computer and the second string in the list is for the script that you want to execute. You can use an absolute path to run scripts in other directories also.

To make a Python script run at Windows Startup you need to find the startup folder in your computer and place a batch file in it. A google search tell you where it is for your version of Windows.

Use notepad++ to makeĀ  a .bat file(Just use Save as and select .bat instead of .txt). In that file write

python "<Path to you Python file>/<name_of_python_script>.py"

Here you have to write the ” on either side as I have written. That makes it possible for you to just copy and paste the path to your scripts.

Advertisements