/
folderScan.py
130 lines (100 loc) · 3.67 KB
/
folderScan.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import settings
import os
import os.path
import log
rootFolder = settings.scanDir
find = settings.illegals
depth = 0
zips = settings.zips
#print('Scanning', rootFolder)
# Scan the Suffix Folders
def scanFolder(folder):
badFiles = []
#flag = 0
for dirpath, dirnames, filenames in os.walk(folder):
for filename in [f for f in filenames if f.endswith(find)]:
#flag = 1
toLog = (os.path.join(dirpath, filename))
log.logger(toLog)
#badFiles.append((dirpath, filename))
badFiles.append(toLog)
#print(badFiles)
if badFiles:
return badFiles
#Scan the the main folder ignoring suffixes
def scanFolderIgnore(folder):
#flag = 0
badFiles = []
for dirpath, dirs, filenames in os.walk(folder,topdown=True):
dirs[:] = [d for d in dirs if d not in settings.exclude]
for filename in [f for f in filenames if f.endswith(find)]:
#flag =1
toLog = (os.path.join(dirpath, filename))
log.logger(toLog)
#badFolder = (os.path.join(dirpath))
#badFiles.append((dirpath,filename))
badFiles.append(toLog)
#print(badFiles)
if badFiles:
return badFiles
""" Here starts zip search """
# Scan the Suffix Folders
def scanFolderZip(folder):
folders = []
zipFiles = []
paths =[]
for dirpath, dirnames, filenames in os.walk(folder):
folders.append(dirpath)
for filename in [f for f in filenames if f.endswith(zips)]:
filename = filename.split('.',1)[0]
toLog = (os.path.join(dirpath, filename))
zipFiles.append(filename)
paths.append(toLog)
""" Get the bad paths"""
basePath = []
ofZip = []
duplicatedZips = set(paths) & set(folders)
#Dealing with the paths for easy finding
for path in duplicatedZips:
trim = os.path.basename(os.path.normpath(path))
trimlen = len(trim)
path = path[:-trimlen]
basePath.append(path)
ofZip.append(trim)
#Gather all Data
#print("Please Look in", path, "\n for ", trim, "and ", trim+".zip")
#print("They appear to be extracted zips ie duplicates. Please remove either the folder or the zip or I will remove you!")
if duplicatedZips:
return (basePath,ofZip)
#Scan the the main folder ignoring suffixes
def scanFolderIgnoreZip(folder):
folders = []
zipFiles = []
paths =[]
for dirpath, dirs, filenames in os.walk(folder,topdown=True):
dirs[:] = [d for d in dirs if d not in settings.exclude]
folders.append(dirpath)
for filename in [f for f in filenames if f.endswith(zips)]:
filename = filename.split('.',1)[0]
toLog = (os.path.join(dirpath, filename))
zipFiles.append(filename)
paths.append(toLog)
""" Get the bad paths"""
basePath = []
ofZip = []
duplicatedZips = set(paths) & set(folders)
#Dealing with the paths for easy finding
for path in duplicatedZips:
trim = os.path.basename(os.path.normpath(path))
trimlen = len(trim)
path = path[:-trimlen]
basePath.append(path)
ofZip.append(trim)
#Gather all Data
#print("Please Look in", path, "\n for ", trim, "and ", trim+".zip")
#print("They appear to be extracted zips ie duplicates. Please remove either the folder or the zip or I will remove you!")
if duplicatedZips:
return (basePath,ofZip)
""" Testing Ground """
# demo = 'J:\\2014\\14250'
# scanFolderZip(demo)