Skip to content

Commit

Permalink
added Path.resolve() in some missed functions
Browse files Browse the repository at this point in the history
  • Loading branch information
niradar committed Jun 19, 2024
1 parent 216b9b6 commit b713079
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions duplicate_files_in_folders/file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,12 @@ def get_file_info(file_path: str) -> Dict:
:param file_path: path to the file
:return: dictionary with file information
"""
file_path = Path(file_path).resolve()

stats = os.stat(file_path)
return {
'path': file_path,
'name': os.path.basename(file_path),
'path': str(file_path),
'name': file_path.name,
'size': stats.st_size,
'modified_time': stats.st_mtime,
'created_time': stats.st_ctime
Expand All @@ -216,6 +218,7 @@ def list_tree_os_scandir_bfs(directory: str | Path, raise_on_permission_error: b
:param raise_on_permission_error: if True, raise a PermissionError if a directory cannot be accessed
:return: generator of file paths
"""
directory = str(Path(directory).resolve()) # use the absolute path, but convert it to a string to avoid issues
queue = deque([directory])
while queue:
current_dir = queue.popleft()
Expand All @@ -235,13 +238,15 @@ def list_tree_os_scandir_bfs(directory: str | Path, raise_on_permission_error: b
@staticmethod
def get_files_and_stats(directory: str | Path, raise_on_permission_error: bool = False) -> List[Dict]:
"""
Get file information for all files in a directory and its subdirectories. Optimized for speed.
Get file information for all files in a directory and its subdirectories. Optimized for speed by not using
generators and returning a list of dictionaries with file information.
:param directory: path to the directory
:param raise_on_permission_error: if True, raise a PermissionError if a directory cannot be accessed
:return: list of dictionaries with file information
:raises: PermissionError if a directory cannot be accessed and raise_on_permission_error is True
"""
files_stats = []
directory = str(Path(directory).resolve()) # use the absolute path, but convert it to a string to avoid issues
queue = deque([directory])
while queue:
current_dir = queue.popleft()
Expand Down

0 comments on commit b713079

Please sign in to comment.