I can check the presence of a file or folder using OS library very easily. The following two links have described that directoryExistance fileExistance
I am attempting to use the subprocess library to do the same
and, I tried a couple of approaches already
1- status = subprocess.call(['test','-e',<path>])
, which is always returning 1, no matter what I pass in path.
2- Using getstatusoutput,
/bin/sh: 1: : Permission denied
status, result = subprocess.getstatusoutput([<path>]) print(status) print(result)
which is working fine because status variable returns 126 if the file/folder exist and 127 when the file/folder doesn't exist. Also the result variable contains message but the "result" variable contains the message : Permission denied
But the second solution looks like a hack to me. Is their a better way, of doing this ?