OCISDK/OCISDK/ObjectStorage/IO/ObjectStorageDirectoryInfo.cs
/// <summary>
/// Deletes all the files in this directory as well as this directory.  If recursive is set to true then all sub directories will be 
/// deleted as well.
/// </summary>
/// <exception cref="T:System.Net.WebException"></exception>
Deletes all the files in this directory as well as this directory.  If recursive is set to true then all sub directories will be
deleted as well.
Deletes all the files in this directory as well as this directory . If recursive is set to true then all sub directories will be deleted as well .
public void Delete(bool recursive)
        {
            if (String.IsNullOrEmpty(BucketName))
            {
                throw new NotSupportedException();
            }
            if (recursive)
            {
                ListObjectsRequest listRequest = new ListObjectsRequest
                {
                    NamespaceName = NamespaceName,
                    BucketName = BucketName,
                    Prefix = ObjectStorageHelper.EncodeKey(ObjectKey)
                };
                DeleteObjectsRequest deleteRequest = new DeleteObjectsRequest
                {
                    NamespaceName = NamespaceName,
                    BucketName = BucketName,
                    Objects = new List<TargetDelete>()
                };
                ListObjectsResponse listResponse;
                do
                {
                    listResponse = Client.ListObjects(listRequest);
                    foreach (var obj in listResponse.ListObjects.Objects)
                    {
                        deleteRequest.Objects.Add(new TargetDelete { ObjectName = obj.Name });
                        if (deleteRequest.Objects.Count >= MULTIPLE_OBJECT_DELETE_LIMIT)
                        {
                            Client.DeleteObjects(deleteRequest);
                            deleteRequest.Objects.Clear();
                        }
                    }
                    if (string.IsNullOrEmpty(listResponse.ListObjects.NextStartWith))
                    {
                        break;
                    }
                    else
                    {
                        listRequest.Start = listResponse.ListObjects.NextStartWith;
                    }
                } while (true);
                if (deleteRequest.Objects.Count > 0)
                {
                    Client.DeleteObjects(deleteRequest);
                }
            }
            if (String.IsNullOrEmpty(ObjectKey) && Exists)
            {
                var request = new DeleteBucketRequest { NamespaceName = NamespaceName, BucketName = BucketName };
                Client.DeleteBucket(request);
            }
            else
            {
                if (!EnumerateFileSystemInfos().GetEnumerator().MoveNext() && Exists)
                {
                    var request = new DeleteObjectRequest
                    {
                        NamespaceName = NamespaceName,
                        BucketName = BucketName,
                        ObjectName = ObjectStorageHelper.EncodeKey(ObjectKey)
                    };
                    Client.DeleteObject(request);
                }
            }
        }
public void Delete ( bool recursive ) { if ( String . IsNullOrEmpty ( BucketName ) ) { throw new NotSupportedException ( ) ; } if ( recursive ) { ListObjectsRequest listRequest = new ListObjectsRequest { NamespaceName = NamespaceName , BucketName = BucketName , Prefix = ObjectStorageHelper . EncodeKey ( ObjectKey ) } ; DeleteObjectsRequest deleteRequest = new DeleteObjectsRequest { NamespaceName = NamespaceName , BucketName = BucketName , Objects = new List < TargetDelete > ( ) } ; ListObjectsResponse listResponse ; do { listResponse = Client . ListObjects ( listRequest ) ; foreach ( var obj in listResponse . ListObjects . Objects ) { deleteRequest . Objects . Add ( new TargetDelete { ObjectName = obj . Name } ) ; if ( deleteRequest . Objects . Count >= MULTIPLE_OBJECT_DELETE_LIMIT ) { Client . DeleteObjects ( deleteRequest ) ; deleteRequest . Objects . Clear ( ) ; } } if ( string . IsNullOrEmpty ( listResponse . ListObjects . NextStartWith ) ) { break ; } else { listRequest . Start = listResponse . ListObjects . NextStartWith ; } } while ( true ) ; if ( deleteRequest . Objects . Count > 0 ) { Client . DeleteObjects ( deleteRequest ) ; } } if ( String . IsNullOrEmpty ( ObjectKey ) && Exists ) { var request = new DeleteBucketRequest { NamespaceName = NamespaceName , BucketName = BucketName } ; Client . DeleteBucket ( request ) ; } else { if ( ! EnumerateFileSystemInfos ( ) . GetEnumerator ( ) . MoveNext ( ) && Exists ) { var request = new DeleteObjectRequest { NamespaceName = NamespaceName , BucketName = BucketName , ObjectName = ObjectStorageHelper . EncodeKey ( ObjectKey ) } ; Client . DeleteObject ( request ) ; } } }
Deletes all the files in this directory as well as this directory.
Deletes all the files in this directory as well as this directory .
None
recursive
bool