summaryrefslogtreecommitdiff
path: root/Chap9PracSelectiveCopy.py
blob: 9464f7e4a80cd8786a31669a7f670b4dc83f8e0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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')