@@ -151,18 +151,29 @@ def _resolve_folder_id(self, drive_type: str, folder_path: str):
151151 if folder_path is None or folder_path == '/' :
152152 return 'root'
153153
154+ path_parts = folder_path .strip ('/' ).split ('/' )
155+ # Find the first part that doesn't contain a wildcard
156+ valid_path_parts = []
157+ for part in path_parts :
158+ if '*' in part or '?' in part :
159+ break
160+ valid_path_parts .append (part )
161+
162+ # Use only the valid path parts for the API request
163+ valid_path = '/' .join (valid_path_parts )
164+
154165 drive_root = f"{ self .base_url } /{ 'root' if drive_type == 'ofb' else 'drive/root' } "
155- url = f"{ drive_root } :/{ folder_path . strip ( '/' ) } :/"
166+ url = f"{ drive_root } :/{ valid_path } :/" if valid_path else f" { drive_root } : "
156167 response = self .get_request (url , is_absolute_path = True )
157168
158169 if response :
159170 if response .status_code == 200 :
160171 return response .json ()['id' ]
161172 else :
162- raise OneDriveClientException (f"Error resolving folder path '{ folder_path } ': "
173+ raise OneDriveClientException (f"Error resolving folder path '{ valid_path } ': "
163174 f"{ response .status_code } , { response .text } " )
164175 else :
165- raise OneDriveClientException (f"Cannot find { folder_path } . Please verify if this path exists." )
176+ raise OneDriveClientException (f"Cannot find { valid_path } . Please verify if this path exists." )
166177
167178 def _get_folder_contents_onedrive (self , drive_type : str , folder_id : str ):
168179 if folder_id == 'root' :
@@ -354,17 +365,17 @@ def _create_folder_mask(mask, folder_path):
354365 def _process_items (self , items , folder_mask , mask , folder_path , output_dir , last_modified_at , library_name ):
355366 for item in items :
356367 if item .get ('folder' ):
357- self ._process_folder_item (
358- item ,
359- folder_mask ,
360- mask ,
361- folder_path ,
362- output_dir ,
363- last_modified_at ,
364- library_name
365- )
368+ if fnmatch .fnmatch (item ['name' ], folder_mask ):
369+ self ._process_folder_item (
370+ item ,
371+ folder_mask ,
372+ mask ,
373+ folder_path ,
374+ output_dir ,
375+ last_modified_at ,
376+ library_name
377+ )
366378 else :
367- # For files, we need to check if they match the pattern
368379 if fnmatch .fnmatch (item ['name' ], mask ):
369380 self ._process_file_item (item , mask , output_dir , last_modified_at )
370381
@@ -414,13 +425,14 @@ def get_document_libraries(self, site_url):
414425 return response .json ()['value' ]
415426
416427 def download_files (self , file_path , output_dir , last_modified_at = None , library_name : str = None ):
417- if not last_modified_at :
418- last_modified_at = datetime .strptime ("2000-01-01T00:00:00" , "%Y-%m-%dT%H:%M:%S" )
428+ self .file_mask = file_path
419429 folder_path , mask = self ._split_path_mask (file_path )
420- logging .info (f"Downloading files matching mask { mask } from folder { folder_path } " )
430+
431+ # Get the folder contents
421432 items = self ._get_items_based_on_client_type (folder_path , library_name )
422- folder_mask = self ._create_folder_mask (mask , folder_path )
423- self ._process_items (items , folder_mask , mask , folder_path , output_dir , last_modified_at , library_name )
433+
434+ # Process the items
435+ self ._process_items (items , folder_path , mask , folder_path , output_dir , last_modified_at , library_name )
424436
425437 @property
426438 def get_freshest_file_timestamp (self ):
0 commit comments