import os
def normalize_filepath(filepath):
"""Normalizes a file path to a consistent format."""
filepath = os.path.abspath(filepath) # Get absolute path
filepath = os.path.normpath(filepath) # Remove redundant separators
return filepath
def normalize_filepaths(filepaths):
"""Normalizes a list of file paths."""
normalized_paths = []
for filepath in filepaths:
normalized_paths.append(normalize_filepath(filepath))
return normalized_paths
if __name__ == '__main__':
# Example usage
paths = [
"/path/to/my/file.txt",
"../another/file.txt",
"./relative/path/file.txt",
"/path/to/my/file.txt" #duplicate to test
]
normalized_paths = normalize_filepaths(paths)
for path in normalized_paths:
print(path)
Add your comment