1313
1414
1515def parsefolder (folder ):
16- folder = folder .strip ()
17- if folder .endswith ("/" ):
18- folder = folder [:- 1 ]
16+ # Remove trailing spaces and slashes
17+ folder = folder .strip ().rstrip ("\\ /" )
1918 if not os .path .exists (folder ):
2019 raise Exception (f"folder does not exist. { folder } " )
2120 files = _list_files (folder )
@@ -53,8 +52,12 @@ def _list_files(folder):
5352 for root , dirs , files in os .walk (folder ):
5453 for file in files :
5554 file_path = os .path .join (root , file )
56- filedescriptors .append (_describe_file (file_path .split (folder )[1 ]))
57- filedescriptors = sorted (filedescriptors , key = lambda x : _alphanumkey (x ["file" ]))
55+ rel = os .path .relpath (file_path , folder )
56+ filedescriptors .append (_describe_file (f"/{ rel } " ))
57+ filedescriptors = sorted (
58+ filedescriptors ,
59+ key = lambda x : _alphanumkey (x ["file" ]),
60+ )
5861 return filedescriptors
5962
6063
@@ -64,7 +67,7 @@ def _add_indices(files):
6467
6568
6669def _describe_file (f ):
67- name = f . split ( "/" )[ - 1 ]
70+ name = os . path . basename ( f )
6871 dirname = os .path .dirname (f )
6972 fullkey , extension = os .path .splitext (f )
7073 fullkey2 = fullkey .replace ("/labels" , "" ).replace ("/images" , "" )
0 commit comments