Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2024 01:47 PM - edited 06-10-2024 01:48 PM
Trabaja, "casi" perfectamente. La verdad el código tiene un bug en el recorrido, el cual se corrige cambiando la línea "elif child.path != node.path:" por "else:". Adicionalmente, se puede mejorar incluyendo el envio del flag verbose.
Quedaría...
from dbruntime.dbutils import FileInfo
def get_size_of_path(path, verbose=False):
return sum([file.size for file in get_all_files_in_path(path, verbose)])
def get_all_files_in_path(path, verbose=False):
nodes_new = []
nodes_new = dbutils.fs.ls(path)
files = []
while len(nodes_new) > 0:
current_nodes = nodes_new
nodes_new = []
for node in current_nodes:
if verbose:
print(f"Processing {node.path}")
children = dbutils.fs.ls(node.path)
for child in children:
if verbose:
print(f"Processing {child.path} [{child.size} bytes] in {node.path}")
if child.size == 0 and child.path != node.path:
nodes_new.append(child)
#elif child.path != node.path:
else:
files.append(child)
return files