add scanning
This commit is contained in:
parent
aa503a4234
commit
4f294524ca
1 changed files with 19 additions and 16 deletions
|
@ -27,24 +27,27 @@ class find_duplicate_files:
|
|||
self.first_directory = first_directory
|
||||
self.second_directory = second_directory
|
||||
|
||||
first_files = self._find_files(self.first_directory)
|
||||
second_files = self._find_files(self.second_directory)
|
||||
first_files = self.recursive_scandir(self.first_directory)
|
||||
second_files = self.recursive_scandir(self.second_directory)
|
||||
|
||||
def _find_files(self, directory, hidden=False):
|
||||
if os.path.exists(directory):
|
||||
files = list()
|
||||
with os.scandir(directory) as it:
|
||||
for entry in it:
|
||||
if not entry.name.startswith('.') and entry.is_file():
|
||||
file = {
|
||||
'file': entry.name
|
||||
}
|
||||
def recursive_scandir(self, path, ignore_hidden_files=True):
|
||||
''' Recursively scan a directory for files'''
|
||||
files = []
|
||||
try:
|
||||
for file in os.scandir(path):
|
||||
if not file.name.startswith('.'):
|
||||
if file.is_file():
|
||||
files.append(file)
|
||||
self._log.debug(f"Found {len(files)} in '{directory}'")
|
||||
return files
|
||||
else:
|
||||
self._log.error(f"Given path '{directory}' doesn't exist.")
|
||||
sys.exit(1)
|
||||
elif file.is_dir(follow_symlinks=False):
|
||||
more_files = self.recursive_scandir(
|
||||
file.path,
|
||||
ignore_hidden_files=ignore_hidden_files
|
||||
)
|
||||
if more_files:
|
||||
files = files + more_files
|
||||
except PermissionError as error:
|
||||
self._log.warning(f"Permission denied accessing folder '{path}'")
|
||||
return files
|
||||
|
||||
def _init_log(self):
|
||||
''' Initialize log object '''
|
||||
|
|
Loading…
Reference in a new issue