Creating, copying, and deleting files and directories
Operations with files, such as copying, moving, and deleting, or with directories, such as creating, renaming, and deleting, are all supported by the filesystem
library. Files and directories are identified with a path (that can be absolute, canonical, or relative), a topic that was covered in the previous recipes. In this recipe, we will look at what are the standard functions for the above-mentioned operations and how they work.
Getting ready
Before going forward, you should read the Working with filesystem paths recipe. Introductory notes from that recipe also apply here. However, all examples in this recipe are platform independent.
For all the following examples, we will use the following variables, and assume the current path is C:\Users\Marius\Documents
on Windows, and /home/marius/docs
for a POSIX system. We will also assume the presence of the file called sample.txt
in the temp
subdirectory of the current path (such as C:\Users...