Class ShareDirectoryAsyncClient
Instantiating an Asynchronous Directory Client
ShareDirectoryAsyncClient client = new ShareFileClientBuilder() .connectionString("${connectionString}") .endpoint("${endpoint}") .buildDirectoryAsyncClient();
View this
for additional ways to construct the client.
-
Method Summary
Modifier and TypeMethodDescriptioncreate()
Creates this directory in the file share and returns a response ofShareDirectoryInfo
to interact with it.createFile
(String fileName, long maxSize) Creates a file in this directory with specific name, max number of results and returns a response of ShareDirectoryInfo to interact with it.createFileWithResponse
(String fileName, long maxSize, ShareFileHttpHeaders httpHeaders, FileSmbProperties smbProperties, String filePermission, Map<String, String> metadata) Creates a file in this directory with specific name and returns a response of ShareDirectoryInfo to interact with it.createFileWithResponse
(String fileName, long maxSize, ShareFileHttpHeaders httpHeaders, FileSmbProperties smbProperties, String filePermission, Map<String, String> metadata, ShareRequestConditions requestConditions) Creates a file in this directory with specific name and returns a response of ShareDirectoryInfo to interact with it.Creates this directory in the file share if it does not exist.Creates a directory in the file share if it does not exist.createSubdirectory
(String subdirectoryName) Creates a subdirectory under current directory with specific name and returns a response of ShareDirectoryAsyncClient to interact with it.createSubdirectoryIfNotExists
(String subdirectoryName) Creates a subdirectory under current directory with specific name if it does not exist and returns a response of ShareDirectoryAsyncClient to interact with it.createSubdirectoryIfNotExistsWithResponse
(String subdirectoryName, ShareDirectoryCreateOptions options) Creates a subdirectory under current directory with specific name and metadata if it does not exist, and returns a response of ShareDirectoryAsyncClient to interact with it.createSubdirectoryWithResponse
(String subdirectoryName, FileSmbProperties smbProperties, String filePermission, Map<String, String> metadata) Creates a subdirectory under current directory with specific name , metadata and returns a response of ShareDirectoryAsyncClient to interact with it.createWithResponse
(FileSmbProperties smbProperties, String filePermission, Map<String, String> metadata) Creates a directory in the file share and returns a response of ShareDirectoryInfo to interact with it.delete()
Deletes the directory in the file share.deleteFile
(String fileName) Deletes the file with specific name in this directory.deleteFileIfExists
(String fileName) Deletes the file with specific name in this directory if it exists.deleteFileIfExistsWithResponse
(String fileName) Deletes the file with specific name in this directory if it exists.deleteFileIfExistsWithResponse
(String fileName, ShareRequestConditions requestConditions) Deletes the file with specific name in this directory if it exists.deleteFileWithResponse
(String fileName) Deletes the file with specific name in this directory.deleteFileWithResponse
(String fileName, ShareRequestConditions requestConditions) Deletes the file with specific name in this directory.Deletes the directory in the file share if it exists.Deletes the directory in the file share if it exists.deleteSubdirectory
(String subdirectoryName) Deletes the subdirectory with specific name in this directory.deleteSubdirectoryIfExists
(String subdirectoryName) Deletes the subdirectory with specific name in this directory if it exists.deleteSubdirectoryIfExistsWithResponse
(String subdirectoryName) Deletes the subdirectory with specific name in this directory if it exists.deleteSubdirectoryWithResponse
(String subdirectoryName) Deletes the subdirectory with specific name in this directory.Deletes the directory in the file share.exists()
Determines if the directory this client represents exists in the cloud.Determines if the directory this client represents exists in the cloud.forceCloseAllHandles
(boolean recursive) Closes all handles opened on the directory at the service.forceCloseHandle
(String handleId) Closes a handle on the directory.forceCloseHandleWithResponse
(String handleId) Closes a handle on the directory.generateSas
(ShareServiceSasSignatureValues shareServiceSasSignatureValues) Generates a service SAS for the directory using the specifiedShareServiceSasSignatureValues
generateSas
(ShareServiceSasSignatureValues shareServiceSasSignatureValues, Context context) Generates a service SAS for the directory using the specifiedShareServiceSasSignatureValues
Get associated account name.Get directory path of the client.Get the url of the storage directory client.getFileClient
(String fileName) Constructs a ShareFileAsyncClient that interacts with the specified file.Gets theHttpPipeline
powering this client.Retrieves the properties of this directory.Retrieves the properties of this directory.Gets the service version the client is using.Get the share name of directory client.Get snapshot id which attached toShareDirectoryAsyncClient
.getSubdirectoryClient
(String subdirectoryName) Constructs a ShareDirectoryAsyncClient that interacts with the specified directory.Lists all sub-directories and files in this directory without their prefix or maxResults in single page.Lists all sub-directories and files in this directory with their prefix or snapshots.listFilesAndDirectories
(String prefix, Integer maxResultsPerPage) Lists all sub-directories and files in this directory with their prefix or snapshots.listHandles
(Integer maxResultPerPage, boolean recursive) List of open handles on a directory or a file.Moves the directory to another location within the share.renameWithResponse
(ShareFileRenameOptions options) Moves the directory to another location within the share.setMetadata
(Map<String, String> metadata) Sets the user-defined metadata to associate to the directory.setMetadataWithResponse
(Map<String, String> metadata) Sets the user-defined metadata to associate to the directory.setProperties
(FileSmbProperties smbProperties, String filePermission) Sets the properties of this directory.setPropertiesWithResponse
(FileSmbProperties smbProperties, String filePermission) Sets the properties of this directory.
-
Method Details
-
getDirectoryUrl
Get the url of the storage directory client.- Returns:
- the URL of the storage directory client
-
getServiceVersion
Gets the service version the client is using.- Returns:
- the service version the client is using.
-
getFileClient
Constructs a ShareFileAsyncClient that interacts with the specified file.If the file doesn't exist in this directory
ShareFileAsyncClient.create(long)
create} in the client will need to be called before interaction with the file can happen.- Parameters:
fileName
- Name of the file- Returns:
- a ShareFileAsyncClient that interacts with the specified share
-
getSubdirectoryClient
Constructs a ShareDirectoryAsyncClient that interacts with the specified directory.If the file doesn't exist in this directory
create()
create} in the client will need to be called before interaction with the directory can happen.- Parameters:
subdirectoryName
- Name of the directory- Returns:
- a ShareDirectoryAsyncClient that interacts with the specified directory
-
exists
Determines if the directory this client represents exists in the cloud.Code Samples
client.exists().subscribe(response -> System.out.printf("Exists? %b%n", response));
- Returns:
- Flag indicating existence of the directory.
-
existsWithResponse
Determines if the directory this client represents exists in the cloud.Code Samples
client.existsWithResponse().subscribe(response -> System.out.printf("Exists? %b%n", response.getValue()));
- Returns:
- Flag indicating existence of the directory.
-
create
Creates this directory in the file share and returns a response ofShareDirectoryInfo
to interact with it.Code Samples
Create the directory
shareDirectoryAsyncClient.create().subscribe( response -> { }, error -> System.err.print(error.toString()), () -> System.out.println("Completed creating the directory!") );
For more information, see the Azure Docs.
- Returns:
- The
directory info
. - Throws:
ShareStorageException
- If the directory has already existed, the parent directory does not exist or directory name is an invalid resource name.
-
createIfNotExists
Creates this directory in the file share if it does not exist.Code Samples
Create the directory
shareDirectoryAsyncClient.createIfNotExists().subscribe(response -> System.out.printf("Created at %s%n", response.getLastModified()));
For more information, see the Azure Docs.
- Returns:
- A reactive response signaling completion.
ShareDirectoryInfo
contains information about the created directory.
-
delete
Deletes the directory in the file share.Code Samples
Delete the directory
shareDirectoryAsyncClient.delete().subscribe( response -> { }, error -> System.err.println(error.toString()), () -> System.out.println("Completed deleting the file.") );
For more information, see the Azure Docs.
- Returns:
- An empty response.
- Throws:
ShareStorageException
- If the share doesn't exist
-
deleteWithResponse
Deletes the directory in the file share.Code Samples
Delete the directory
shareDirectoryAsyncClient.deleteWithResponse().subscribe( response -> System.out.printf("Delete completed with status code %d", response.getStatusCode()), error -> System.err.println(error.toString()) );
For more information, see the Azure Docs.
- Returns:
- A response that only contains headers and response status code
- Throws:
ShareStorageException
- If the share doesn't exist
-
deleteIfExists
Deletes the directory in the file share if it exists.Code Samples
Delete the directory
shareDirectoryAsyncClient.deleteIfExists().subscribe(deleted -> { if (deleted) { System.out.println("Successfully deleted."); } else { System.out.println("Does not exist."); } });
For more information, see the Azure Docs.
- Returns:
- a reactive response signaling completion.
true
indicates that the directory was successfully deleted,false
indicates that the directory did not exist.
-
deleteIfExistsWithResponse
Deletes the directory in the file share if it exists.Code Samples
Delete the directory
shareDirectoryAsyncClient.deleteIfExistsWithResponse().subscribe(response -> { if (response.getStatusCode() == 404) { System.out.println("Does not exist."); } else { System.out.println("successfully deleted."); } });
For more information, see the Azure Docs.
- Returns:
- A reactive response signaling completion. If
Response
's status code is 202, the directory was successfully deleted. If status code is 404, the directory does not exist.
-
getProperties
Retrieves the properties of this directory. The properties include directory metadata, last modified date, is server encrypted, and eTag.Code Samples
Retrieve directory properties
shareDirectoryAsyncClient.getProperties().subscribe(properties -> { System.out.printf("Directory latest modified date is %s.", properties.getLastModified()); });
For more information, see the Azure Docs.
- Returns:
- Storage directory properties
-
getPropertiesWithResponse
Retrieves the properties of this directory. The properties include directory metadata, last modified date, is server encrypted, and eTag.Code Samples
Retrieve directory properties
shareDirectoryAsyncClient.getPropertiesWithResponse().subscribe(properties -> { System.out.printf("Directory latest modified date is %s:", properties.getValue().getLastModified()); });
For more information, see the Azure Docs.
- Returns:
- A response containing the storage directory properties with headers and response status code
-
setMetadata
Sets the user-defined metadata to associate to the directory.If
null
is passed for the metadata it will clear the metadata associated to the directory.Code Samples
Set the metadata to "directory:updatedMetadata"
shareDirectoryAsyncClient.setMetadata(Collections.singletonMap("directory", "updatedMetadata")) .subscribe(response -> System.out.println("Setting the directory metadata completed."));
Clear the metadata of the directory
shareDirectoryAsyncClient.setMetadata(null) .doOnSuccess(response -> System.out.println("Clearing the directory metadata completed"));
For more information, see the Azure Docs.
- Parameters:
metadata
- Optional metadata to set on the directory, if null is passed the metadata for the directory is cleared- Returns:
- information about the directory
- Throws:
ShareStorageException
- If the directory doesn't exist or the metadata contains invalid keys
-
setMetadataWithResponse
public Mono<Response<ShareDirectorySetMetadataInfo>> setMetadataWithResponse(Map<String, String> metadata) Sets the user-defined metadata to associate to the directory.If
null
is passed for the metadata it will clear the metadata associated to the directory.Code Samples
Set the metadata to "directory:updatedMetadata"
shareDirectoryAsyncClient.setMetadataWithResponse(Collections.singletonMap("directory", "updatedMetadata")) .subscribe(response -> System.out.println("Setting the directory metadata completed with status code:" + response.getStatusCode()));
Clear the metadata of the directory
shareDirectoryAsyncClient.setMetadataWithResponse(null).subscribe( response -> System.out.printf("Clearing the directory metadata completed with status code %d", response.getStatusCode()));
For more information, see the Azure Docs.
- Parameters:
metadata
- Optional metadata to set on the directory, if null is passed the metadata for the directory is cleared- Returns:
- A response containing the information about the directory with headers and response status code
- Throws:
ShareStorageException
- If the directory doesn't exist or the metadata contains invalid keys
-
listFilesAndDirectories
Lists all sub-directories and files in this directory without their prefix or maxResults in single page.Code Samples
List all sub-directories and files in the account
shareDirectoryAsyncClient.listFilesAndDirectories().subscribe( fileRef -> System.out.printf("Is the resource a directory? %b. The resource name is: %s.", fileRef.isDirectory(), fileRef.getName()), error -> System.err.println(error.toString()), () -> System.out.println("Completed listing the directories and files.") );
For more information, see the Azure Docs.
- Returns:
File info
in the storage directory
-
listFilesAndDirectories
Lists all sub-directories and files in this directory with their prefix or snapshots.Code Samples
List all sub-directories with "subdir" prefix and return 10 results in the account
shareDirectoryAsyncClient.listFilesAndDirectories("subdir", 10).subscribe( fileRef -> System.out.printf("Is the resource a directory? %b. The resource name is: %s.", fileRef.isDirectory(), fileRef.getName()), error -> System.err.println(error.toString()), () -> System.out.println("Completed listing the directories and files.") );
For more information, see the Azure Docs.
- Parameters:
prefix
- Optional prefix which filters the results to return only files and directories whose name begins with.maxResultsPerPage
- Optional maximum number of files and/or directories to return per page. If the request does not specify maxResultsPerPage or specifies a value greater than 5,000, the server will return up to 5,000 items.- Returns:
File info
in this directory with prefix and max number of return results.
-
listHandles
List of open handles on a directory or a file.Code Samples
Get 10 handles with recursive call.
shareDirectoryAsyncClient.listHandles(10, true) .subscribe(handleItem -> System.out.printf("Get handles completed with handle id %s", handleItem.getHandleId()));
For more information, see the Azure Docs.
- Parameters:
maxResultPerPage
- Optional maximum number of results will return per pagerecursive
- Specifies operation should apply to the directory specified in the URI, its files, its subdirectories and their files.- Returns:
handles
in the directory that satisfy the requirements
-
forceCloseHandle
Closes a handle on the directory. This is intended to be used alongsidelistHandles(Integer, boolean)
.Code Samples
Force close handles returned by list handles.
shareDirectoryAsyncClient.listHandles(null, true).subscribe(handleItem -> shareDirectoryAsyncClient.forceCloseHandle(handleItem.getHandleId()).subscribe(ignored -> System.out.printf("Closed handle %s on resource %s%n", handleItem.getHandleId(), handleItem.getPath())));
For more information, see the Azure Docs.
- Parameters:
handleId
- Handle ID to be closed.- Returns:
- A response that contains information about the closed handles.
-
forceCloseHandleWithResponse
Closes a handle on the directory. This is intended to be used alongsidelistHandles(Integer, boolean)
.Code Samples
Force close handles returned by list handles.
shareDirectoryAsyncClient.listHandles(null, true).subscribe(handleItem -> shareDirectoryAsyncClient.forceCloseHandleWithResponse(handleItem.getHandleId()).subscribe(response -> System.out.printf("Closing handle %s on resource %s completed with status code %d%n", handleItem.getHandleId(), handleItem.getPath(), response.getStatusCode())));
For more information, see the Azure Docs.
- Parameters:
handleId
- Handle ID to be closed.- Returns:
- A response that contains information about the closed handles along with headers and response status code.
-
forceCloseAllHandles
Closes all handles opened on the directory at the service.Code Samples
Force close all handles recursively.
shareDirectoryAsyncClient.forceCloseAllHandles(true).subscribe(closeHandlesInfo -> System.out.printf("Closed %d open handles on the directory%nFailed to close %d open handles on the " + "directory%n", closeHandlesInfo.getClosedHandles(), closeHandlesInfo.getFailedHandles()));
For more information, see the Azure Docs.
- Parameters:
recursive
- Flag indicating if the operation should apply to all subdirectories and files contained in the directory.- Returns:
- A response that contains information about the closed handles.
-
rename
Moves the directory to another location within the share. For more information see the Azure Docs.Code Samples
ShareDirectoryAsyncClient renamedClient = client.rename(destinationPath).block(); System.out.println("Directory Client has been renamed");
- Parameters:
destinationPath
- Relative path from the share to rename the directory to.- Returns:
- A
Mono
containing aShareDirectoryAsyncClient
used to interact with the new file created.
-
createSubdirectory
Creates a subdirectory under current directory with specific name and returns a response of ShareDirectoryAsyncClient to interact with it.Code Samples
Create the sub directory "subdir"
shareDirectoryAsyncClient.createSubdirectory("subdir") .doOnSuccess(response -> System.out.println("Completed creating the subdirectory."));
For more information, see the Azure Docs.
- Parameters:
subdirectoryName
- Name of the subdirectory- Returns:
- A subdirectory client.
- Throws:
ShareStorageException
- If the subdirectory has already existed, the parent directory does not exist or directory is an invalid resource name.
-
createSubdirectoryIfNotExists
Creates a subdirectory under current directory with specific name if it does not exist and returns a response of ShareDirectoryAsyncClient to interact with it.Code Samples
Create the sub directory "subdir"
shareDirectoryAsyncClient.createSubdirectoryIfNotExists("subdir") .switchIfEmpty(Mono.<ShareDirectoryAsyncClient>empty() .doOnSuccess(x -> System.out.println("Already exists."))) .subscribe(response -> System.out.println("Create completed."));
For more information, see the Azure Docs.
- Parameters:
subdirectoryName
- Name of the subdirectory- Returns:
- A
Mono
containing aShareDirectoryAsyncClient
used to interact with the subdirectory created.
-
deleteSubdirectory
Deletes the subdirectory with specific name in this directory.Code Samples
Delete the subdirectory named "subdir"
shareDirectoryAsyncClient.deleteSubdirectory("mysubdirectory").subscribe( response -> { }, error -> System.err.println(error.toString()), () -> System.out.println("Completed deleting the subdirectory.") );
For more information, see the Azure Docs.
- Parameters:
subdirectoryName
- Name of the subdirectory- Returns:
- An empty response.
- Throws:
ShareStorageException
- If the subdirectory doesn't exist, the parent directory does not exist or subdirectory name is an invalid resource name.
-
deleteSubdirectoryWithResponse
Deletes the subdirectory with specific name in this directory.Code Samples
Delete the subdirectory named "subdir"
shareDirectoryAsyncClient.deleteSubdirectoryWithResponse("mysubdirectory").subscribe( response -> System.out.printf("Delete subdirectory completed with status code %d", response.getStatusCode()), error -> System.err.println(error.toString()), () -> System.out.println("Completed deleting the subdirectory.") );
For more information, see the Azure Docs.
- Parameters:
subdirectoryName
- Name of the subdirectory- Returns:
- A response that only contains headers and response status code
- Throws:
ShareStorageException
- If the subdirectory doesn't exist, the parent directory does not exist or subdirectory name is an invalid resource name.
-
deleteSubdirectoryIfExists
Deletes the subdirectory with specific name in this directory if it exists.Code Samples
Delete the subdirectory named "subdir"
shareDirectoryAsyncClient.deleteSubdirectoryIfExists("mysubdirectory").subscribe(deleted -> { if (deleted) { System.out.println("Successfully deleted."); } else { System.out.println("Does not exist."); } });
For more information, see the Azure Docs.
- Parameters:
subdirectoryName
- Name of the subdirectory- Returns:
- a reactive response signaling completion.
true
indicates that the subdirectory was successfully deleted,false
indicates that the subdirectory did not exist.
-
deleteSubdirectoryIfExistsWithResponse
Deletes the subdirectory with specific name in this directory if it exists.Code Samples
Delete the subdirectory named "subdir"
shareDirectoryAsyncClient.deleteSubdirectoryIfExistsWithResponse("mysubdirectory").subscribe(response -> { if (response.getStatusCode() == 404) { System.out.println("Does not exist."); } else { System.out.println("successfully deleted."); } });
For more information, see the Azure Docs.
- Parameters:
subdirectoryName
- Name of the subdirectory- Returns:
- A reactive response signaling completion. If
Response
's status code is 202, the subdirectory was successfully deleted. If status code is 404, the subdirectory does not exist.
-
createFile
Creates a file in this directory with specific name, max number of results and returns a response of ShareDirectoryInfo to interact with it.Code Samples
Create 1k file with named "myFile"
shareDirectoryAsyncClient.createFile("myfile", 1024).subscribe( response -> { }, error -> System.err.println(error.toString()), () -> System.out.println("Completed creating the file.") );
For more information, see the Azure Docs.
- Parameters:
fileName
- Name of the filemaxSize
- Size of the file- Returns:
- The ShareFileAsyncClient.
- Throws:
ShareStorageException
- If the parent directory does not exist or file name is an invalid resource name.
-
deleteFile
Deletes the file with specific name in this directory.Code Samples
Delete the file "filetest"
shareDirectoryAsyncClient.deleteFile("myfile").subscribe( response -> { }, error -> System.err.println(error.toString()), () -> System.out.println("Completed deleting the file.") );
For more information, see the Azure Docs.
- Parameters:
fileName
- Name of the file- Returns:
- An empty response.
- Throws:
ShareStorageException
- If the directory doesn't exist or the file doesn't exist or file name is an invalid resource name.
-
deleteFileWithResponse
Deletes the file with specific name in this directory.Code Samples
Delete the file "filetest"
shareDirectoryAsyncClient.deleteFileWithResponse("myfile").subscribe( response -> System.out.printf("Delete file completed with status code %d", response.getStatusCode()), error -> System.err.println(error.toString()), () -> System.out.println("Completed deleting the file.") );
For more information, see the Azure Docs.
- Parameters:
fileName
- Name of the file- Returns:
- A response that only contains headers and response status code
- Throws:
ShareStorageException
- If the directory doesn't exist or the file doesn't exist or file name is an invalid resource name.
-
deleteFileIfExists
Deletes the file with specific name in this directory if it exists.Code Samples
Delete the file "filetest"
shareDirectoryAsyncClient.deleteFileIfExists("myfile").subscribe(deleted -> { if (deleted) { System.out.println("Successfully deleted."); } else { System.out.println("Does not exist."); } });
For more information, see the Azure Docs.
- Parameters:
fileName
- Name of the file- Returns:
- a reactive response signaling completion.
true
indicates that the file was successfully deleted,false
indicates that the file did not exist.
-
deleteFileIfExistsWithResponse
Deletes the file with specific name in this directory if it exists.Code Samples
Delete the file "filetest"
shareDirectoryAsyncClient.deleteFileIfExistsWithResponse("myfile").subscribe(response -> { if (response.getStatusCode() == 404) { System.out.println("Does not exist."); } else { System.out.println("successfully deleted."); } });
For more information, see the Azure Docs.
- Parameters:
fileName
- Name of the file- Returns:
- A reactive response signaling completion. If
Response
's status code is 202, the file was successfully deleted. If status code is 404, the file does not exist.
-
getDirectoryPath
Get directory path of the client.Get directory path.
String directoryPath = shareDirectoryAsyncClient.getDirectoryPath(); System.out.println("The name of the directory is " + directoryPath);
- Returns:
- The path of the directory.
-
getAccountName
Get associated account name.- Returns:
- account name associated with this storage resource.
-
getHttpPipeline
Gets theHttpPipeline
powering this client.- Returns:
- The pipeline.
-