MCPcopy Index your code
hub / github.com/FSoft-AI4Code/HyperAgent / find_non_utf8_files

Function find_non_utf8_files

src/hyperagent/utils.py:309–330  ·  view source on GitHub ↗

Finds all non-UTF-8 file paths in a given directory and returns their relative paths. Args: path (str): The path to the directory. Returns: list: A list of relative paths of non-UTF-8 files.

(path)

Source from the content-addressed store, hash-verified

307 return string
308
309def find_non_utf8_files(path):
310 """
311 Finds all non-UTF-8 file paths in a given directory and returns their relative paths.
312
313 Args:
314 path (str): The path to the directory.
315
316 Returns:
317 list: A list of relative paths of non-UTF-8 files.
318 """
319 non_utf8_files = []
320 for root, dirs, files in os.walk(path):
321 for file in files:
322 file_path = os.path.join(root, file)
323 try:
324 with codecs.open(file_path, 'r', 'utf-8') as f:
325 f.read()
326 except UnicodeDecodeError:
327 # Calculate the relative path by removing the base directory path
328 relative_path = os.path.relpath(file_path, path)
329 non_utf8_files.append(relative_path)
330 return non_utf8_files
331
332def find_abs_path(folder, file_name):
333 # Walk through the directory and its subdirectories

Callers 1

__init__Method · 0.90

Calls 2

appendMethod · 0.80
walkMethod · 0.45

Tested by

no test coverage detected