@@ -98,9 +98,9 @@ public IEnumerable<string> GetDirectories(string path)
98
98
{
99
99
ArgumentNullException . ThrowIfNull ( path ) ;
100
100
101
- return ListBlobs ( GetDirectoryPath ( path ) )
101
+ return ListBlobs ( path )
102
102
. Where ( x => x . IsPrefix )
103
- . Select ( x => GetRelativePath ( $ "/ { x . Prefix } " ) . Trim ( '/' ) ) ;
103
+ . Select ( x => GetRelativePath ( x . Prefix ) . TrimEnd ( '/' ) ) ;
104
104
}
105
105
106
106
/// <inheritdoc />
@@ -118,13 +118,9 @@ public void DeleteDirectory(string path, bool recursive)
118
118
{
119
119
ArgumentNullException . ThrowIfNull ( path ) ;
120
120
121
- foreach ( var blob in ListBlobs ( GetDirectoryPath ( path ) ) )
121
+ foreach ( BlobHierarchyItem blob in ListBlobs ( path , true ) )
122
122
{
123
- if ( blob . IsPrefix )
124
- {
125
- DeleteDirectory ( blob . Prefix , true ) ;
126
- }
127
- else if ( blob . IsBlob )
123
+ if ( blob . IsBlob )
128
124
{
129
125
_container . GetBlobClient ( blob . Blob . Name ) . DeleteIfExists ( ) ;
130
126
}
@@ -137,7 +133,7 @@ public bool DirectoryExists(string path)
137
133
{
138
134
ArgumentNullException . ThrowIfNull ( path ) ;
139
135
140
- return GetBlobClient ( GetDirectoryPath ( path ) ) . Exists ( ) ;
136
+ return ListBlobs ( path ) . Any ( ) ;
141
137
}
142
138
143
139
/// <inheritdoc />
@@ -159,10 +155,10 @@ public void AddFile(string path, Stream stream, bool overrideIfExists)
159
155
ArgumentNullException . ThrowIfNull ( path ) ;
160
156
ArgumentNullException . ThrowIfNull ( stream ) ;
161
157
162
- var blob = GetBlobClient ( path ) ;
158
+ BlobClient blob = GetBlobClient ( path ) ;
163
159
if ( ! overrideIfExists && blob . Exists ( ) )
164
160
{
165
- throw new InvalidOperationException ( $ "A file at path '{ path } ' already exists") ;
161
+ throw new InvalidOperationException ( $ "A file at path '{ path } ' already exists. ") ;
166
162
}
167
163
168
164
var headers = new BlobHttpHeaders ( ) ;
@@ -187,10 +183,10 @@ public void AddFile(string path, string physicalPath, bool overrideIfExists = tr
187
183
ArgumentNullException . ThrowIfNull ( path ) ;
188
184
ArgumentNullException . ThrowIfNull ( physicalPath ) ;
189
185
190
- var destinationBlob = GetBlobClient ( path ) ;
186
+ BlobClient destinationBlob = GetBlobClient ( path ) ;
191
187
if ( ! overrideIfExists && destinationBlob . Exists ( ) )
192
188
{
193
- throw new InvalidOperationException ( $ "A file at path '{ path } ' already exists") ;
189
+ throw new InvalidOperationException ( $ "A file at path '{ path } ' already exists. ") ;
194
190
}
195
191
196
192
var sourceBlob = GetBlobClient ( physicalPath ) ;
@@ -227,15 +223,15 @@ public IEnumerable<string> GetFiles(string path, string? filter)
227
223
{
228
224
ArgumentNullException . ThrowIfNull ( path ) ;
229
225
230
- var files = ListBlobs ( GetDirectoryPath ( path ) ) . Where ( x => x . IsBlob ) . Select ( x => x . Blob . Name ) ;
226
+ IEnumerable < string > files = ListBlobs ( path ) . Where ( x => x . IsBlob ) . Select ( x => x . Blob . Name ) ;
231
227
if ( ! string . IsNullOrEmpty ( filter ) && filter != "*.*" )
232
228
{
233
229
// TODO: Might be better to use a globbing library
234
230
filter = filter . TrimStart ( "*" ) ;
235
231
files = files . Where ( x => x . IndexOf ( filter , StringComparison . InvariantCultureIgnoreCase ) > - 1 ) ;
236
232
}
237
233
238
- return files . Select ( x => GetRelativePath ( $ "/ { x } " ) ) ;
234
+ return files . Select ( GetRelativePath ) ;
239
235
}
240
236
241
237
/// <inheritdoc />
@@ -337,7 +333,7 @@ public BlobClient GetBlobClient(string path)
337
333
{
338
334
ArgumentNullException . ThrowIfNull ( path ) ;
339
335
340
- return _container . GetBlobClient ( GetBlobPath ( path ) ) ;
336
+ return _container . GetBlobClient ( GetBlobName ( path ) ) ;
341
337
}
342
338
343
339
/// <inheritdoc />
@@ -346,19 +342,15 @@ public BlobClient GetBlobClient(string path)
346
342
private static string EnsureUrlSeparatorChar ( string path )
347
343
=> path . Replace ( "\\ " , "/" , StringComparison . InvariantCultureIgnoreCase ) ;
348
344
349
- private string GetDirectoryPath ( string fullPathOrUrl )
345
+ private Pageable < BlobHierarchyItem > ListBlobs ( string path , bool recursive = false )
350
346
{
351
- var path = GetFullPath ( fullPathOrUrl ) ;
347
+ string ? delimiter = recursive ? null : "/" ;
348
+ string prefix = GetFullPath ( path ) . EnsureEndsWith ( '/' ) ;
352
349
353
- return path . Length == 0 ? path : path . EnsureEndsWith ( '/' ) ;
354
- }
355
-
356
- private IEnumerable < BlobHierarchyItem > ListBlobs ( string path )
357
- {
358
- return _container . GetBlobsByHierarchy ( prefix : path ) ;
350
+ return _container . GetBlobsByHierarchy ( delimiter : delimiter , prefix : prefix ) ;
359
351
}
360
352
361
- private string GetBlobPath ( string path )
353
+ private string GetBlobName ( string path )
362
354
{
363
355
path = EnsureUrlSeparatorChar ( path ) ;
364
356
0 commit comments