| 1 |
ninoborges |
8 |
"""
|
| 2 |
|
|
Version .01
|
| 3 |
|
|
Created by Emanuel Borges
|
| 4 |
|
|
|
| 5 |
|
|
This program will try to copy the items in the main.txt file, putting the found stuff in
|
| 6 |
|
|
one file and the not found in another. It preserves the file path and lets you use an
|
| 7 |
|
|
exclude list.
|
| 8 |
|
|
"""
|
| 9 |
|
|
|
| 10 |
|
|
import os, shutil
|
| 11 |
|
|
|
| 12 |
|
|
mainFile = open(r"\\ercdis12\Admin\share\Manny\WIP\Nap\Search_List.txt",'r').readlines()
|
| 13 |
|
|
foundFile = open(r"c:\test_dir\Nap\found.txt",'w')
|
| 14 |
|
|
not_foundFile = open(r"c:\test_dir\Nap\notFound.txt",'w')
|
| 15 |
|
|
not_foundExcludedFile = open(r"c:\test_dir\Nap\EXCLUDED\notFound.txt",'w')
|
| 16 |
|
|
exclude_List_temp = open(r"\\ercdis12\Admin\share\Manny\WIP\Nap\Exclude_List.txt",'r').readlines()
|
| 17 |
|
|
|
| 18 |
|
|
|
| 19 |
|
|
exclude_List = []
|
| 20 |
|
|
for line in exclude_List_temp:
|
| 21 |
|
|
exclude_List.append(line.upper())
|
| 22 |
|
|
|
| 23 |
|
|
for line in mainFile:
|
| 24 |
|
|
if line.upper() in exclude_List:
|
| 25 |
|
|
workingDir = "c:\\test_dir\Nap\EXCLUDED"
|
| 26 |
|
|
excludedFlag = True
|
| 27 |
|
|
else:
|
| 28 |
|
|
workingDir = "c:\\test_dir\Nap"
|
| 29 |
|
|
excludedFlag = False
|
| 30 |
|
|
|
| 31 |
|
|
line = line.split('\n')[0]
|
| 32 |
|
|
#file = "D:\\"+ file
|
| 33 |
|
|
try:
|
| 34 |
|
|
filePath, file = os.path.split(line)
|
| 35 |
|
|
|
| 36 |
|
|
if os.path.exists(workingDir + os.path.splitdrive(filePath)[1]) == 0:
|
| 37 |
|
|
os.makedirs(workingDir + os.path.splitdrive(filePath)[1])
|
| 38 |
|
|
print "now copying %s to %s"% (filePath + "\\"+ file, workingDir + os.path.splitdrive(filePath)[1])
|
| 39 |
|
|
shutil.copy2(filePath + "\\"+ file, workingDir + os.path.splitdrive(filePath)[1])
|
| 40 |
|
|
foundFile.write(os.path.splitdrive(filePath)[1] + "\\" + file + "\n")
|
| 41 |
|
|
except:
|
| 42 |
|
|
if excludedFlag:
|
| 43 |
|
|
not_foundExcludedFile.write(os.path.splitdrive(filePath)[1] + "\\" + file + "\n")
|
| 44 |
|
|
else:
|
| 45 |
|
|
not_foundFile.write(os.path.splitdrive(filePath)[1] + "\\" + file + "\n")
|
| 46 |
|
|
|
| 47 |
|
|
#mainFile.close()
|
| 48 |
|
|
foundFile.close()
|
| 49 |
|
|
not_foundFile.close()
|
| 50 |
|
|
not_foundExcludedFile.close() |