I have a script in python.
I read some path folder from a csv file.
I wish to create a loop to do something like that: "cd" into some folders (I read the path from the csv file) and execute some bash command.
The problem is that I don't know how to go back in the "home" folder to start the loop again.
The code exit with error because don't find the path to folder after chdir in the first folder.
Can someone help me please?
import csv
import os
import subprocess
def subprocess_cmd(command):
process = subprocess.Popen(command,stdout=subprocess.PIPE, shell=True)
proc_stdout = process.communicate()[0].strip()
print(proc_stdout)
with open("esempio.csv", "r") as f_input:
csv_input = csv.DictReader(f_input)
aaa = []
for row in csv_input:
path = row['folder']
lang1 = row['lang1']
name1 = row['name1']
lang2 = row['lang2']
name2 = row['name2']
aaa.append(path)
for path in aaa:
os.chdir(path)
subprocess_cmd('touch aaa')