I think this should help:
The script will use os.walk
, as @1_CR suggested, and will call hello_world.py
script with the path to both files when fna
and faa
files exist together (i.e. in same direcotry).
import glob, os
def scanfolder():
for path, dirs, files in os.walk('/home/shadowe/test1/test1/'):
flag_faa = 0
flag_fna = 0
for f in files:
if f.endswith('.faa'):
flag_faa = 1
faa_file_path = os.path.join(path,f)
if f.endswith('.fna'):
flag_fna = 1
fna_file_path = os.path.join(path,f)
if flag_faa == 1 and flag_fna == 1:
print "Calling script"
os.system("python hello_world.py" + " -a "+ faa_file_path + " -b " + fna_file_path)
flag_faa = 0
flag_fna = 0
scanfolder()
Second script:
import sys
print "Hello World"
print "This argument passing qualifies " + sys.argv[1] + " " + sys.argv[2] + " " + sys.argv[3] + " " + sys.argv[4]
Output:
$ python test.py
Calling script
Hello World
This argument passing qualifies -a /home/shadowe/test1/test1/test2/test3/two.faa -b /home/shadowe/test1/test1/test2/test3/two.fna
Calling script
Hello World
This argument passing qualifies -a /home/shadowe/test1/test1/test6/test7/four.faa -b /home/shadowe/test1/test1/test6/test7/five.fna
script.py
? Why not useos.walk
to navigate the directory from withinscript.py
?folder
anddirectory
in your question. Is there a difference between those two things? If so, what is the difference? Also, please edit your question to include a portion of an example directory structure for us to look at.script.py
takes file names or directories? Do.fna
and.faa
come in pairs?