filmov
tv
Python Modules #7.4: OS - How to work with files and directories in Python?

Показать описание
In this video, we're going to learn how to use the os module to work with files and directories.
If you're looking to learn more about Python modules, then this is the video for you! In this video, we'll cover everything from files to directories manipulating. By the end of this video, you'll have a solid understanding of how to use the os module to work with files and directories you need and manipulate data in Python!
0:00 Introduction
1:49 Change the current working directory to path. This function can support specifying a file descriptor. The descriptor must refer to an opened directory, not an open file.
3:13 Create a hard link pointing to src named dst. This function can support specifying src_dir_fd and/or dst_dir_fd to supply paths relative to directory descriptors, and not following symlinks.
3:46 Create a symbolic link pointing to src named dst. On Windows, a symlink represents either a file or a directory, and does not morph to the target dynamically. If the target is present, the type of the symlink will be created to match.
5:24 If path is of type bytes (directly or indirectly through the PathLike interface), the filenames returned will also be of type bytes; in all other circumstances, they will be of type str. This function can also support specifying a file descriptor; the file descriptor must refer to a directory.
8:11 Recursive directory creation function. Like mkdir(), but makes all intermediate-level directories needed to contain the leaf directory. The mode parameter is passed to mkdir() for creating the leaf directory; see the mkdir() description for how it is interpreted.
10:15 Remove directories recursively. Works like rmdir() except that, if the leaf directory is successfully removed, removedirs() tries to successively remove every parent directory mentioned in path until an error is raised
10:54 Rename the file or directory src to dst. This function can support specifying src_dir_fd and/or dst_dir_fd to supply paths relative to directory descriptors. If dst exists, the operation will fail with an OSError subclass in a number of cases
12:25 Recursive directory or file renaming function. Works like rename(), except creation of any intermediate directories needed to make the new pathname good is attempted first.
13:31 Get the status of a file or a file descriptor. Perform the equivalent of a stat() system call on the given path. path may be specified as either a string or bytes - directly or indirectly through the PathLike interface- or as an open file descriptor. Return a stat result object.
16:42 Remove (delete) the file path. This function is semantically identical to remove(); the unlink name is its traditional Unix name.
17:16 Set the access and modified times of the file specified by path. utime() takes two optional parameters, times and ns. These specify the times set on path and are used as follows
18:28 Generate the file names in a directory tree by walking the tree either top-down or bottom-up. For each directory in the tree rooted at directory top (including top itself), it yields a 3-tuple (dirpath, dirnames, filenames).
19:02 If optional argument topdown is True or not specified, the triple for a directory is generated before the triples for any of its subdirectories (top-down). If topdown is False, the triple for a directory is generated after the triples for all of its subdirectories (bottom-up).
For the image on the preview we thank to Inna:
For the music we thank to AntipodeanWriter:
Playlists:
LinkedIn group (Coding Thoughts):
Thank you for watching. Please, support the channel by like to let the more people see this video. Leave comment. Share. Subscribe to the channel.
If you're looking to learn more about Python modules, then this is the video for you! In this video, we'll cover everything from files to directories manipulating. By the end of this video, you'll have a solid understanding of how to use the os module to work with files and directories you need and manipulate data in Python!
0:00 Introduction
1:49 Change the current working directory to path. This function can support specifying a file descriptor. The descriptor must refer to an opened directory, not an open file.
3:13 Create a hard link pointing to src named dst. This function can support specifying src_dir_fd and/or dst_dir_fd to supply paths relative to directory descriptors, and not following symlinks.
3:46 Create a symbolic link pointing to src named dst. On Windows, a symlink represents either a file or a directory, and does not morph to the target dynamically. If the target is present, the type of the symlink will be created to match.
5:24 If path is of type bytes (directly or indirectly through the PathLike interface), the filenames returned will also be of type bytes; in all other circumstances, they will be of type str. This function can also support specifying a file descriptor; the file descriptor must refer to a directory.
8:11 Recursive directory creation function. Like mkdir(), but makes all intermediate-level directories needed to contain the leaf directory. The mode parameter is passed to mkdir() for creating the leaf directory; see the mkdir() description for how it is interpreted.
10:15 Remove directories recursively. Works like rmdir() except that, if the leaf directory is successfully removed, removedirs() tries to successively remove every parent directory mentioned in path until an error is raised
10:54 Rename the file or directory src to dst. This function can support specifying src_dir_fd and/or dst_dir_fd to supply paths relative to directory descriptors. If dst exists, the operation will fail with an OSError subclass in a number of cases
12:25 Recursive directory or file renaming function. Works like rename(), except creation of any intermediate directories needed to make the new pathname good is attempted first.
13:31 Get the status of a file or a file descriptor. Perform the equivalent of a stat() system call on the given path. path may be specified as either a string or bytes - directly or indirectly through the PathLike interface- or as an open file descriptor. Return a stat result object.
16:42 Remove (delete) the file path. This function is semantically identical to remove(); the unlink name is its traditional Unix name.
17:16 Set the access and modified times of the file specified by path. utime() takes two optional parameters, times and ns. These specify the times set on path and are used as follows
18:28 Generate the file names in a directory tree by walking the tree either top-down or bottom-up. For each directory in the tree rooted at directory top (including top itself), it yields a 3-tuple (dirpath, dirnames, filenames).
19:02 If optional argument topdown is True or not specified, the triple for a directory is generated before the triples for any of its subdirectories (top-down). If topdown is False, the triple for a directory is generated after the triples for all of its subdirectories (bottom-up).
For the image on the preview we thank to Inna:
For the music we thank to AntipodeanWriter:
Playlists:
LinkedIn group (Coding Thoughts):
Thank you for watching. Please, support the channel by like to let the more people see this video. Leave comment. Share. Subscribe to the channel.
Комментарии