Searching files based on extension using os.path
<p>I was wondering how to search for files based on their extension. If you were to search for py or txt or some other extension, the user would input it and then it would search for it. I'm not allowed to use glob nor os.walk</p>

<p>This is the method I have. If necessary, I'll post the whole code.</p>

<p>The user first inputs a directory which is in another method after that, they would say</p>

<p>E txt or E .txt (both works) and it would return the files based on what extension you used. I'm not sure what's wrong with my code though.</p>

<p>In your code,</p>

<pre><code> for file in directory 
</code></pre>

<p>is definitely wrong, as directory is a string with the path in it. it should be something like </p>

<pre><code>for file in os.listdir(directory):
</code></pre>

<p>to get a list of files in the directory </p>

python os.path