How to archive files with Python – Archiviare file con Python

Python to archive files

archive python shutil os glob
archive python shutil os glob

Module to import

First, let’s impor os, glob and shutil

  • os, to get the path of the files and to create the folder “archive” if not present
  • glob to select all the txt files
  • shutil to move the files in the dir “archive”

Iteration

With the for (each) loop we move each file in archive.

try except

If there is no folder “archive”, it is created

Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.