I have a python script and I wrote it such that it will generate an output file to a new directory called test using these two lines:
self.mkdir_p("test") # create directory named "test"
file_out = open("test/"+input,"w")
and the mkdir_p function is as follow:
def mkdir_p(self,path):
try:
os.makedirs(path)
except OSError as exc:
if exc.errno == errno.EEXIST:
pass
else: raise
Now, I have all the files that I would like my script to run on stored in directory called storage, and my question is, how can I write a script such that I can run all the files in storage from my home directory(where my python script is located), and saved all the output to the test directory as I coded in my python script?
I did a naive approach in bash like:
#!/bin/bash
# get the directory name where the files are stored (storage)
in=$1
# for files in (storage) directory
for f in $1/*
do
echo "Processing $f file..."
./my_python_script.py $f
done
and it didnt work and threw IOError: No such file or directory: 'test/storage/inputfile.txt'
I hope I explained my problem clear enough.
Thanks in advance
$fisstorage/inputfile.txtand Python prependstest/to that, then complains becausetest/storagedoes not exist. Create the directory, or strip the directory part before creating the output file name.