From 5766c5365854e8eafa33a5b087d418789d359679 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Sat, 21 Dec 2019 02:12:28 +0100 Subject: [PATCH] Working on path --- README.md | 71 ++++++++++++++++++++++++++++-------------------------- index.html | 57 ++++++++++++++++++++++--------------------- parse.js | 2 +- 3 files changed, 67 insertions(+), 63 deletions(-) diff --git a/README.md b/README.md index b0625ad..7e32576 100644 --- a/README.md +++ b/README.md @@ -1576,8 +1576,8 @@ from glob import glob ``` ```python - = listdir('') # List of filenames located at path. - = glob('') # Filenames matching the wildcard pattern. + = listdir('') # Returns filenames located at path. + = glob('') # Returns paths matching the wildcard pattern. ``` ### Pathlib @@ -1586,11 +1586,16 @@ from pathlib import Path ``` ```python -cwd = Path() = Path('' [, '', , ...]) = / '' / '' ``` +```python + = Path() # Or: Path('.') + = .resolve() # Returns absolute Path without symlinks. + = .parent # Returns path without final component. +``` + ```python = .exists() = .is_file() @@ -1598,24 +1603,42 @@ cwd = Path() ``` ```python - = .iterdir() # Returns dir contents as Path objects. - = .glob('') # Returns Paths matching the wildcard pattern. + = .iterdir() # Returns dir contents as relative (not true) Path objects. + = .glob('') # Returns relative Paths matching the wildcard pattern. ``` ```python - = str() # Path as a string. - = .name # Final component. - = .stem # Final component without extension. - = .suffix # Final component's extension. - = .parts # All components as strings. + = str() # Returns Path as a string. + = .name # Returns final component. + = .stem # Returns final component without extension. + = .suffix # Returns final component's extension. + = .parts # Returns all components as strings. ``` ```python - = .resolve() # Returns absolute path without symlinks. - = .parent # Returns path without final component. = open() # Opens the file and returns a file object. ``` +### DirEntry +```python + = os.scandir(path='.') # Returns DirEntry objects located at path. +``` + +```python + = .is_file() + = .is_dir() +``` + +```python + = .path # Returns relative path as a string. + = .name # Returns final component. +``` + +```python + = Path() # Returns relative Path object. + = open() # Opens the file and returns a file object. +``` + OS Commands ----------- @@ -1634,7 +1657,7 @@ os.mkdir(, mode=0o777) # Creates a directory. Mode is in octal. ```python shutil.copy(from, to) # Copies the file. -shutil.copytree(from, to) # Copies the entire directory tree. +shutil.copytree(from, to) # Copies the directory. ``` ```python @@ -1645,27 +1668,7 @@ os.replace(from, to) # Same, but overwrites 'to' if it exists. ```python os.remove() # Deletes the file. os.rmdir() # Deletes empty directory. -shutil.rmtree() # Deletes the entire directory tree. -``` - -```python - = os.scandir(path='.') # Returns os.DirEntry objects located at path. -``` - -#### DirEntry: -```python - = .is_file() - = .is_dir() -``` - -```python - = .path # Path as a string. - = .name # Final component. -``` - -```python - = Path() # Path object. - = open() # File object. +shutil.rmtree() # Deletes non-empty directory. ``` ### Shell Commands diff --git a/index.html b/index.html index cab27a7..29c4bd9 100644 --- a/index.html +++ b/index.html @@ -1453,32 +1453,45 @@ value = args.<name> <bool> = path.isfile('<path>') <bool> = path.isdir('<path>') -
<list> = listdir('<path>')          # List of filenames located at path.
-<list> = glob('<pattern>')          # Filenames matching the wildcard pattern.
+
<list> = listdir('<path>')          # Returns filenames located at path.
+<list> = glob('<pattern>')          # Returns paths matching the wildcard pattern.
 

Pathlib

from pathlib import Path
 
-
cwd    = Path()
-<Path> = Path('<path>' [, '<path>', <Path>, ...])
+
<Path> = Path('<path>' [, '<path>', <Path>, ...])
 <Path> = <Path> / '<dir>' / '<file>'
 
+
<Path> = Path()                     # Or: Path('.')
+<Path> = <Path>.resolve()           # Returns absolute Path without symlinks.
+<Path> = <Path>.parent              # Returns path without final component.
+
<bool> = <Path>.exists()
 <bool> = <Path>.is_file()
 <bool> = <Path>.is_dir()
 
-
<iter> = <Path>.iterdir()           # Returns dir contents as Path objects.
-<iter> = <Path>.glob('<pattern>')   # Returns Paths matching the wildcard pattern.
+
<iter> = <Path>.iterdir()           # Returns dir contents as relative (not true) Path objects.
+<iter> = <Path>.glob('<pattern>')   # Returns relative Paths matching the wildcard pattern.
 
-
<str>  = str(<Path>)                # Path as a string.
-<str>  = <Path>.name                # Final component.
-<str>  = <Path>.stem                # Final component without extension.
-<str>  = <Path>.suffix              # Final component's extension.
-<tup.> = <Path>.parts               # All components as strings.
+
<str>  = str(<Path>)                # Returns Path as a string.
+<str>  = <Path>.name                # Returns final component.
+<str>  = <Path>.stem                # Returns final component without extension.
+<str>  = <Path>.suffix              # Returns final component's extension.
+<tup.> = <Path>.parts               # Returns all components as strings.
 
-
<Path> = <Path>.resolve()           # Returns absolute path without symlinks.
-<Path> = <Path>.parent              # Returns path without final component.
-<file> = open(<Path>)               # Opens the file and returns a file object.
+
<file> = open(<Path>)               # Opens the file and returns a file object.
+
+

DirEntry

<iter> = os.scandir(path='.')       # Returns DirEntry objects located at path.
+
+ +
<bool> = <DirEntry>.is_file()
+<bool> = <DirEntry>.is_dir()
+
+
<str>  = <DirEntry>.path            # Returns relative path as a string.
+<str>  = <DirEntry>.name            # Returns final component.
+
+
<Path> = Path(<DirEntry>)           # Returns relative Path object.
+<file> = open(<DirEntry>)           # Opens the file and returns a file object.
 

#OS Commands

Files and Directories

  • Paths can be either strings, Paths, or DirEntry objects.
  • @@ -1492,26 +1505,14 @@ value = args.<name> os.mkdir(<path>, mode=0o777) # Creates a directory. Mode is in octal.
shutil.copy(from, to)               # Copies the file.
-shutil.copytree(from, to)           # Copies the entire directory tree.
+shutil.copytree(from, to)           # Copies the directory.
 
os.rename(from, to)                 # Renames the file or directory.
 os.replace(from, to)                # Same, but overwrites 'to' if it exists.
 
os.remove(<path>)                   # Deletes the file.
 os.rmdir(<path>)                    # Deletes empty directory.
-shutil.rmtree(<path>)               # Deletes the entire directory tree.
-
-
<iter> = os.scandir(path='.')       # Returns os.DirEntry objects located at path.
-
-

DirEntry:

<bool> = <DirEntry>.is_file()
-<bool> = <DirEntry>.is_dir()
-
- -
<str>  = <DirEntry>.path            # Path as a string.
-<str>  = <DirEntry>.name            # Final component.
-
-
<Path> = Path(<DirEntry>)           # Path object.
-<file> = open(<DirEntry>)           # File object.
+shutil.rmtree(<path>)               # Deletes non-empty directory.
 

Shell Commands

import os
 <str> = os.popen('<shell_command>').read()
diff --git a/parse.js b/parse.js
index ee32e3d..f97094e 100755
--- a/parse.js
+++ b/parse.js
@@ -36,7 +36,7 @@ const OS_RENAME =
 
 const SHUTIL_COPY = 
   'shutil.copy(from, to)               # Copies the file.\n' +
-  'shutil.copytree(from, to)           # Copies the entire directory tree.\n';
+  'shutil.copytree(from, to)           # Copies the directory.\n';
 
 const EVAL =
   '>>> from ast import literal_eval\n' +