From 75a42ec54dbf721caa659ddf02c1f46fc2cb4bef Mon Sep 17 00:00:00 2001 From: mlot Date: Fri, 6 Jun 2025 13:40:57 -0400 Subject: initial commit for archiving --- Chap9PracSelectiveCopy.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Chap9PracSelectiveCopy.py (limited to 'Chap9PracSelectiveCopy.py') diff --git a/Chap9PracSelectiveCopy.py b/Chap9PracSelectiveCopy.py new file mode 100644 index 0000000..9464f7e --- /dev/null +++ b/Chap9PracSelectiveCopy.py @@ -0,0 +1,19 @@ +#!python + +# Chapter 9 Practice Selective Copy +# Walks through a directory tree searching for pdf files and copies them to a new location + +import os +import shutil + +def selectiveCopy(folder): + folder = os.path.abspath(folder) + for foldername, subfolders, filenames in os.walk(folder): + for filename in filenames: + if not filename.endswith('.pdf'): + continue + #shutil.copy(filename, 'c:\\pdffolder') #Commented out to protect against accidental copying + print('Copying ' + filename + '...') #Print only to verify working correctly + +selectiveCopy(r'C:\Users\username\pdffolder') +print('Done') -- cgit