diff options
Diffstat (limited to 'Chap9PracSelectiveCopy.py')
-rw-r--r-- | Chap9PracSelectiveCopy.py | 19 |
1 files changed, 19 insertions, 0 deletions
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') |