<pre><codeclass="python language-python hljs"><str> = getcwd() <spanclass="hljs-comment"># Returns the current working directory.</span>
<str> = path.join(<spanclass="hljs-string">'<path>'</span>, ...) <spanclass="hljs-comment"># Joins two or more pathname components.</span>
<str> = path.abspath(<spanclass="hljs-string">'<path>'</span>)<spanclass="hljs-comment"># Return an absolute path.</span>
<str> = path.join(<path>, ...)<spanclass="hljs-comment"># Joins two or more pathname components.</span>
<str> = path.abspath(<path>) <spanclass="hljs-comment"># Return an absolute path.</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>
<tup.> = path.splitext(<spanclass="hljs-string">'<path>'</span>)<spanclass="hljs-comment"># Splits on last period of final component.</span>
<pre><codeclass="python language-python hljs"><str> = path.basename(<path>) <spanclass="hljs-comment"># Returns final component.</span>
<str> = path.dirname(<path>) <spanclass="hljs-comment"># Returns path without final component.</span>
<tup.> = path.splitext(<path>) <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>
<pre><codeclass="python language-python hljs"><list> = listdir(<path>) <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>
<pre><codeclass="python language-python hljs"><str> = str(<Path>) <spanclass="hljs-comment"># Returns Path as a string.</span>
<str> = <Path>.name <spanclass="hljs-comment"># Returns final component.</span>
<pre><codeclass="python language-python hljs"><str> = <Path>.name <spanclass="hljs-comment"># Returns final component.</span>
<str> = <Path>.stem <spanclass="hljs-comment"># Returns final component without extension.</span>
<str> = <Path>.suffix <spanclass="hljs-comment"># Returns final component's extension.</span>
<tup.> = <Path>.parts <spanclass="hljs-comment"># Returns all components as strings.</span>
</code></pre>
<pre><codeclass="python language-python hljs"><file> = open(<Path>) <spanclass="hljs-comment"># Opens the file and returns a file object.</span>
<pre><codeclass="python language-python hljs"><iter> = <Path>.iterdir() <spanclass="hljs-comment"># Returns dir contents as Path objects.</span>
<iter> = <Path>.glob(<spanclass="hljs-string">'<pattern>'</span>) <spanclass="hljs-comment"># Returns Paths matching the wildcard pattern.</span>
<pre><codeclass="python language-python hljs"><str> = str(<Path>) <spanclass="hljs-comment"># Returns Path as a string.</span>
<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() 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>