Nymbo commited on
Commit
9de5ddd
·
verified ·
1 Parent(s): a9f4e48

Update Modules/File_System.py

Browse files
Files changed (1) hide show
  1. Modules/File_System.py +10 -45
Modules/File_System.py CHANGED
@@ -214,51 +214,16 @@ def _display_path(abs_path: str) -> str:
214
 
215
 
216
  def _list_dir(abs_path: str, *, show_hidden: bool, recursive: bool, max_entries: int) -> str:
217
- lines: list[str] = []
218
- total = 0
219
- root_display = "/"
220
- listing_display = _display_path(abs_path)
221
- for root, dirs, files in os.walk(abs_path):
222
- # filter hidden
223
- if not show_hidden:
224
- dirs[:] = [d for d in dirs if not d.startswith('.')]
225
- files = [f for f in files if not f.startswith('.')]
226
- try:
227
- rel_root = os.path.relpath(root, ROOT_DIR)
228
- except Exception:
229
- rel_root = root
230
- rel_root_disp = "/" if rel_root == "." else "/" + rel_root.replace("\\", "/")
231
- lines.append(f"\n📂 {rel_root_disp}")
232
- # sort
233
- dirs.sort()
234
- files.sort()
235
- for d in dirs:
236
- p = os.path.join(root, d)
237
- try:
238
- mtime = datetime.fromtimestamp(os.path.getmtime(p)).isoformat(sep=' ', timespec='seconds')
239
- except Exception:
240
- mtime = "?"
241
- lines.append(f" • [DIR] {d} (modified {mtime})")
242
- total += 1
243
- if total >= max_entries:
244
- lines.append(f"\n… Truncated at {max_entries} entries.")
245
- return "\n".join(lines).strip()
246
- for f in files:
247
- p = os.path.join(root, f)
248
- try:
249
- size = _fmt_size(os.path.getsize(p))
250
- mtime = datetime.fromtimestamp(os.path.getmtime(p)).isoformat(sep=' ', timespec='seconds')
251
- except Exception:
252
- size, mtime = "?", "?"
253
- lines.append(f" • {f} ({size}, modified {mtime})")
254
- total += 1
255
- if total >= max_entries:
256
- lines.append(f"\n… Truncated at {max_entries} entries.")
257
- return "\n".join(lines).strip()
258
- if not recursive:
259
- break
260
- header = f"Listing of {listing_display}\nRoot: {root_display}\nEntries: {total}"
261
- return (header + "\n" + "\n".join(lines)).strip()
262
 
263
 
264
  def _search_text(
 
214
 
215
 
216
  def _list_dir(abs_path: str, *, show_hidden: bool, recursive: bool, max_entries: int) -> str:
217
+ from ._tree_utils import format_dir_listing
218
+
219
+ return format_dir_listing(
220
+ abs_path,
221
+ _display_path(abs_path),
222
+ show_hidden=show_hidden,
223
+ recursive=recursive,
224
+ max_entries=max_entries,
225
+ fmt_size_fn=_fmt_size,
226
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
227
 
228
 
229
  def _search_text(