Files and Folders

Files and Folders: Paths and Folders with pathlib, Copying, Moving and Renaming Files Safely.

Updated

  1. Paths and Folders with pathlib (Apprentice): A Path from Python's pathlib module holds a file's or folder's address in parts, so a script can join paths with /, read a file's name and extension, list and find the files in a folder, and make folders, the same way on Windows and on a Mac.
  2. Copying, Moving and Renaming Files Safely (Journeyman): shutil.copy2 copies a file, shutil.move and Path.rename move and rename one, and three habits keep a file-moving script safe, a backup copy, a check that the destination is free, and a dry run that shows the plan before anything moves.