@@ -312,7 +312,6 @@ public unsafe (string? v, Exception? ex) FileFullPath
312312 }
313313 }
314314
315- // TODO: leverage GetFileInformationByHandleEx
316315 public ( string ? v , Exception ? ex ) FileName
317316 {
318317 get
@@ -322,15 +321,37 @@ public unsafe (string? v, Exception? ex) FileFullPath
322321 const string errUnableMsg = "Unable to query " + nameof ( FileName ) + "; " ;
323322 if ( FileFullPath . v is not null )
324323 {
325- return fileName = ( Path . GetFileName ( FileFullPath . v ) , null ) ;
324+ getFileOrDirectoryName ( FileFullPath . v ) ;
325+ return fileName ;
326+ }
327+ else if ( FileNameInfo . v is not null )
328+ {
329+ getFileOrDirectoryName ( FileNameInfo . v ) ;
330+ return fileName ;
326331 }
327332 else if ( ObjectName . v is not null )
328333 {
329- return fileName = ( Path . GetFileName ( ObjectName . v ) , null ) ;
334+ getFileOrDirectoryName ( ObjectName . v ) ;
335+ return fileName ;
330336 }
331337 else
332338 {
333- return fileName = ( null , new InvalidOperationException ( errUnableMsg + "This operation requires FileFullPath or ObjectName." ) ) ;
339+ return fileName = ( null , new InvalidOperationException ( errUnableMsg + "This operation requires FileFullPath, FileNameInfo, or ObjectName." ) ) ;
340+ }
341+
342+ void getFileOrDirectoryName ( string path )
343+ {
344+ string ? tmp = Path . GetFileName ( path ) ;
345+ if ( tmp . Length is 0 )
346+ {
347+ fileName = ( tmp = Path . GetDirectoryName ( path ) ) is null
348+ ? ( null , new InvalidOperationException ( errUnableMsg + $ "'{ path } ' could not be processed for a file or directory name.") )
349+ : ( tmp , null ) ;
350+ }
351+ else
352+ {
353+ fileName = ( tmp , null ) ;
354+ }
334355 }
335356 }
336357 else
0 commit comments