**Using scandir() instead of listdir() can significantly increase the performance of code that also needs file type or file attribute information.**
**Using scandir() instead of listdir() or iterdir() can significantly increase the performance of code that also needs file type or file attribute information.**
```python
<iter> = os.scandir(path='.') # Returns DirEntry objects located at path.
<pre><codeclass="python language-python hljs"><str> = path.basename(<spanclass="hljs-string">'<path>'</span>)<spanclass="hljs-comment"># Returns final component.</span>
<str> = path.dirname(<spanclass="hljs-string">'<path>'</span>)<spanclass="hljs-comment"># Returns path without final component.</span>
<tup.> = path.splitext(<spanclass="hljs-string">'<path>'</span>)<spanclass="hljs-comment"># Splits on last period of final component.</span>
</code></pre>
<pre><codeclass="python language-python hljs"><list> = listdir(<spanclass="hljs-string">'<path>'</span>) <spanclass="hljs-comment"># Returns filenames located at path.</span>
<list> = glob(<spanclass="hljs-string">'<pattern>'</span>) <spanclass="hljs-comment"># Returns paths matching the wildcard pattern.</span>
</code></pre>
<pre><codeclass="python language-python hljs"><str> = path.basename(<spanclass="hljs-string">'<path>'</span>) <spanclass="hljs-comment"># Returns final component.</span>
<str> = path.dirname(<spanclass="hljs-string">'<path>'</span>) <spanclass="hljs-comment"># Returns path without final component.</span>
<str> = path.splitext(<spanclass="hljs-string">'<path>'</span>)[<spanclass="hljs-number">1</span>] <spanclass="hljs-comment"># Returns final component's extension.</span>
<pre><codeclass="python language-python hljs"><file> = open(<Path>) <spanclass="hljs-comment"># Opens the file and returns a file object.</span>
</code></pre>
<div><h3id="direntry">DirEntry</h3><p><strong>Using scandir() instead of listdir() can significantly increase the performance of code that also needs file type or file attribute information.</strong></p><pre><codeclass="python language-python hljs"><iter> = os.scandir(path=<spanclass="hljs-string">'.'</span>) <spanclass="hljs-comment"># Returns DirEntry objects located at path.</span>
<div><h3id="direntry">DirEntry</h3><p><strong>Using scandir() instead of listdir() or iterdir() can significantly increase the performance of code that also needs file type or file attribute information.</strong></p><pre><codeclass="python language-python hljs"><iter> = os.scandir(path=<spanclass="hljs-string">'.'</span>) <spanclass="hljs-comment"># Returns DirEntry objects located at path.</span>