Skip to content

Commit 1e33b43

Browse files
committed
dir_tree backend improvement
1 parent 5d73d34 commit 1e33b43

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

flaskcode/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def write_file(content, filepath, encoding='utf-8', chunk_size=None):
3636
def dir_tree(abs_path, abs_root_path, exclude_names=None, excluded_extensions=None, allowed_extensions=None):
3737
tree = dict(
3838
name=os.path.basename(abs_path),
39-
path_name=abs_path[len(abs_root_path):].replace('\\', '/').lstrip('/'), # TODO: use os.path.relpath
39+
path_name=os.path.relpath(abs_path, abs_root_path).replace('\\', '/').lstrip('/'),
4040
children=[]
4141
)
4242
try:
@@ -61,7 +61,7 @@ def dir_tree(abs_path, abs_root_path, exclude_names=None, excluded_extensions=No
6161
continue
6262
tree['children'].append(dict(
6363
name=os.path.basename(new_path),
64-
path_name=new_path[len(abs_root_path):].replace('\\', '/').lstrip('/'), # TODO: use os.path.relpath
64+
path_name=os.path.relpath(new_path, abs_root_path).replace('\\', '/').lstrip('/'),
6565
is_file=True,
6666
))
6767
return tree

0 commit comments

Comments
 (0)