Skip to content
Advertisement

search by subproces in dir and return non-zero error

i want to make a program to search all my pc and make list of result , so first of all i can not search all partition together and have to use os.chdir("") on the other hand when some Suffix dose not exit in it make a error and stop program.

My code:

JavaScript

And result:

JavaScript

What sould i do to debug and improve my code!!

Advertisement

Answer

Your problem is you’re using check_output() which will raise an exception if the command returns a non-zero error code, and dir does that if it finds no files that match.

You should use getoutput if you don’t care about that.

However, there’s really no need to shell out to dir 5 times here – just use os.walk():

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement