|
1445 | 1445 | </code></pre>
|
1446 | 1446 | <div><h2 id="commandexecution"><a href="#commandexecution" name="commandexecution">#</a>Command Execution</h2><div><h3 id="filesanddirectories">Files and Directories</h3><ul>
|
1447 | 1447 | <li><strong>Paths can be either strings, Paths, or DirEntry objects.</strong></li>
|
1448 |
| -<li><strong>All exceptions are either 'OSError' or its subclasses.</strong></li> |
1449 |
| -</ul><pre><code class="python language-python hljs"><span class="hljs-keyword">import</span> os |
| 1448 | +<li><strong>All exceptions are either OSError or its subclasses.</strong></li> |
| 1449 | +</ul><pre><code class="python language-python hljs"><span class="hljs-keyword">import</span> os, shutil |
1450 | 1450 | <str> = os.getcwd() <span class="hljs-comment"># Returns the current working directory.</span>
|
1451 | 1451 | os.chdir(<path>) <span class="hljs-comment"># Changes current working directory.</span>
|
1452 | 1452 | </code></pre></div></div>
|
1453 | 1453 |
|
1454 | 1454 |
|
1455 | 1455 |
|
| 1456 | +<pre><code class="python language-python hljs">shutil.copy(from, to) <span class="hljs-comment"># Copies the file.</span> |
| 1457 | +os.rename(from, to) <span class="hljs-comment"># Renames the file or directory.</span> |
| 1458 | +os.replace(from, to) <span class="hljs-comment"># Same, but overwrites 'to' if it exists.</span> |
| 1459 | +</code></pre> |
1456 | 1460 | <pre><code class="python language-python hljs">os.remove(<path>) <span class="hljs-comment"># Deletes the file.</span>
|
1457 | 1461 | os.rmdir(<path>) <span class="hljs-comment"># Deletes empty directory.</span>
|
1458 | 1462 | shutil.rmtree(<path>) <span class="hljs-comment"># Deletes the entire directory tree.</span>
|
1459 | 1463 | </code></pre>
|
1460 |
| -<pre><code class="python language-python hljs">os.rename(from, to) <span class="hljs-comment"># Renames the file or directory.</span> |
1461 |
| -os.replace(from, to) <span class="hljs-comment"># Same, but overwrites 'to' if it exists.</span> |
1462 |
| -</code></pre> |
1463 | 1464 | <pre><code class="python language-python hljs">os.mkdir(<path>, mode=<span class="hljs-number">0o777</span>) <span class="hljs-comment"># Creates a directory.</span>
|
1464 | 1465 | <iter> = os.scandir(path=<span class="hljs-string">'.'</span>) <span class="hljs-comment"># Returns os.DirEntry objects located at path.</span>
|
1465 | 1466 | </code></pre>
|
|
0 commit comments