I have the following code:
import os, glob
from obspy.core import read
for fname in glob.glob('BC.*'):
arch=fname.split('.')
print "<==== ", fname
# Quita la extension (.msd), si existe
if(len(arch) > 7):
del arch[-1]
newName = '.'.join(arch)
st = read(fname)
segmentos = len(st)
# cuenta el numero de segmentos del archivo para hacer el cambio en cada uno de ellos
for i in range(0, segmentos):
st[i].stats.network=arch[0]
st[i].stats.station=arch[1]
st[i].stats.location=arch[2]
st[i].stats.channel=arch[3]
print "====> ", newName , " Ok"
st.write(newName, format="MSEED")
print " --- ", fname, " [x]"
os.remove(fname)
It works well, just to run the script I have to be inside the folder that will make the change, and it is tedious to be running the script inside each folder.
How could I make you go through all the folders without having to put it inside it?
I have the folders like this:
C:\Datos\TEST1\DatosTest1
\TEST2\DatosTest2
\TEST3\DatosTest3