I have a python script which takes the filename as a command argument and processes that file. However, i have thousands of files I need to process, and I would like to run the script on every file without having to add the filename as the argument each time.
The script works well when run on an individual file like this:
myscript.py /my/folder/of/stuff/text1.txt
I have this code to do them all at once, but it doesn't work
for fname in glob.iglob(os.path.join('folder/location')):
proc = subprocess.Popen([sys.executable, 'script/location.py', fname])
proc.wait()
Whenever I run the above code, it doesn't throw an error, but doesn't give me the intended output. I think the problem lies with the fact that the script is expecting the path to a .txt file as an argument, and the code is only giving it the folder that the file is sitting in (or at least not a working absolute reference).
How to correct this problem?