I am using python to read 2 files from my linux os. One contains a single entry/number ‘DATE’:
20111125
the other file contains many entries, ‘TIME’:
042844UTC 044601UTC ... 044601UTC
I am able to read the files to assign to proper variables. I would like to then use the variables to create folder paths, move files etc… such as:
$PATH/20111125/042844UTC $PATH/20111125/044601UTC $PATH/20111125/044601UTC
and so on.
Somehow this doesn’t work with multiple variables passed at once:
import subprocess, sys, os, os.path
DATEFILE = open('/Astronomy/Sorted/2-Scratch/MAPninox-DATE.txt', "r")
TIMEFILE = open('/Astronomy/Sorted/2-Scratch/MAPninox-TIME.txt', "r")
for DATE in DATEFILE:
print DATE,
for TIME in TIMEFILE:
os.popen('mkdir -p /Astronomy/' + DATE + '/' TIME) # this line works for DATE only
os.popen('mkdir -p /Astronomy/20111126/' + TIME) # this line works for TIME only
subprocess.call(['mkdir', '-p', '/Astronomy/', DATE]), #THIS LINE DOESN'T WORK
Thanks!
I would suggest using
os.makedirs(which does the same thing asmkdir -p) instead ofsubprocessorpopen:Then use
shutilfor anycp/mv/etc operations.From the
osDocs: