Class ShareDirectoryClient
Instantiating an Synchronous Directory Client
ShareDirectoryClient client = new ShareFileClientBuilder()
.connectionString("${connectionString}")
.endpoint("${endpoint}")
.buildDirectoryClient();
View this for additional ways to construct the client.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptioncreate()Creates a directory in the file share and returns a response ofShareDirectoryInfoto 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.com.azure.core.http.rest.Response<ShareFileClient> createFileWithResponse(String fileName, long maxSize, ShareFileHttpHeaders httpHeaders, FileSmbProperties smbProperties, String filePermission, Map<String, String> metadata, ShareRequestConditions requestConditions, Duration timeout, com.azure.core.util.Context context) Creates a file in this directory with specific name and returns a response of ShareDirectoryInfo to interact with it.com.azure.core.http.rest.Response<ShareFileClient> createFileWithResponse(String fileName, long maxSize, ShareFileHttpHeaders httpHeaders, FileSmbProperties smbProperties, String filePermission, Map<String, String> metadata, Duration timeout, com.azure.core.util.Context context) Creates a file in this directory with specific name and returns a response of ShareDirectoryInfo to interact with it.Creates a directory in the file share if it does not exist.com.azure.core.http.rest.Response<ShareDirectoryInfo> createIfNotExistsWithResponse(ShareDirectoryCreateOptions options, Duration timeout, com.azure.core.util.Context context) 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 ShareDirectoryClient to interact with it.createSubdirectoryIfNotExists(String subdirectoryName) Creates a subdirectory under current directory with specified name if it does not exist.com.azure.core.http.rest.Response<ShareDirectoryClient> createSubdirectoryIfNotExistsWithResponse(String subdirectoryName, ShareDirectoryCreateOptions options, Duration timeout, com.azure.core.util.Context context) Creates a subdirectory under current directory with specific name and metadata if it does not exist.com.azure.core.http.rest.Response<ShareDirectoryClient> createSubdirectoryWithResponse(String subdirectoryName, FileSmbProperties smbProperties, String filePermission, Map<String, String> metadata, Duration timeout, com.azure.core.util.Context context) Creates a subdirectory under current directory with specific name , metadata and returns a response of ShareDirectoryClient to interact with it.com.azure.core.http.rest.Response<ShareDirectoryInfo> createWithResponse(FileSmbProperties smbProperties, String filePermission, Map<String, String> metadata, Duration timeout, com.azure.core.util.Context context) Creates a directory in the file share and returns a response of ShareDirectoryInfo to interact with it.com.azure.core.http.rest.Response<ShareDirectoryInfo> createWithResponse(ShareDirectoryCreateOptions options, Duration timeout, com.azure.core.util.Context context) Creates a directory in the file share and returns a response of ShareDirectoryInfo to interact with it.voiddelete()Deletes the directory in the file share.voiddeleteFile(String fileName) Deletes the file with specific name in this directory.booleandeleteFileIfExists(String fileName) Deletes the file with specific name in this directory if it exists.com.azure.core.http.rest.Response<Boolean> deleteFileIfExistsWithResponse(String fileName, ShareRequestConditions requestConditions, Duration timeout, com.azure.core.util.Context context) Deletes the file with specific name in this directory if it exists.com.azure.core.http.rest.Response<Boolean> deleteFileIfExistsWithResponse(String fileName, Duration timeout, com.azure.core.util.Context context) Deletes the file with specific name in this directory if it exists.com.azure.core.http.rest.Response<Void> deleteFileWithResponse(String fileName, ShareRequestConditions requestConditions, Duration timeout, com.azure.core.util.Context context) Deletes the file with specific name in this directory.com.azure.core.http.rest.Response<Void> deleteFileWithResponse(String fileName, Duration timeout, com.azure.core.util.Context context) Deletes the file with specific name in this directory.booleanDeletes the directory in the file share if it exists.com.azure.core.http.rest.Response<Boolean> deleteIfExistsWithResponse(Duration timeout, com.azure.core.util.Context context) Deletes the directory in the file share if it exists.voiddeleteSubdirectory(String subdirectoryName) Deletes the subdirectory with specific name in this directory.booleandeleteSubdirectoryIfExists(String subdirectoryName) Deletes the subdirectory with specific name in this directory if it exists.com.azure.core.http.rest.Response<Boolean> deleteSubdirectoryIfExistsWithResponse(String subdirectoryName, Duration timeout, com.azure.core.util.Context context) Deletes the subdirectory with specific name in this directory if it exists.com.azure.core.http.rest.Response<Void> deleteSubdirectoryWithResponse(String subdirectoryName, Duration timeout, com.azure.core.util.Context context) Deletes the subdirectory with specific name in this directory.com.azure.core.http.rest.Response<Void> deleteWithResponse(Duration timeout, com.azure.core.util.Context context) Deletes the directory in the file share.exists()Determines if the directory this client represents exists in the cloud.com.azure.core.http.rest.Response<Boolean> existsWithResponse(Duration timeout, com.azure.core.util.Context context) Determines if the directory this client represents exists in the cloud.forceCloseAllHandles(boolean recursive, Duration timeout, com.azure.core.util.Context context) Closes all handles opened on the directory at the service.forceCloseHandle(String handleId) Closes a handle on the directory at the service.com.azure.core.http.rest.Response<CloseHandlesInfo> forceCloseHandleWithResponse(String handleId, Duration timeout, com.azure.core.util.Context context) Closes a handle on the directory at the service.generateSas(ShareServiceSasSignatureValues shareServiceSasSignatureValues) Generates a service SAS for the directory using the specifiedShareServiceSasSignatureValuesgenerateSas(ShareServiceSasSignatureValues shareServiceSasSignatureValues, com.azure.core.util.Context context) Generates a service SAS for the directory using the specifiedShareServiceSasSignatureValuesgenerateSas(ShareServiceSasSignatureValues shareServiceSasSignatureValues, Consumer<String> stringToSignHandler, com.azure.core.util.Context context) Generates a service SAS for the directory using the specifiedShareServiceSasSignatureValuesGet associated account name.Get the directory path of the client.Get the url of the storage directory client.getFileClient(String fileName) Constructs a ShareFileClient that interacts with the specified file.com.azure.core.http.HttpPipelineGets theHttpPipelinepowering this client.Retrieves the properties of this directory.com.azure.core.http.rest.Response<ShareDirectoryProperties> getPropertiesWithResponse(Duration timeout, com.azure.core.util.Context context) 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 toShareDirectoryClient.getSubdirectoryClient(String subdirectoryName) Constructs a ShareDirectoryClient that interacts with the specified directory.com.azure.core.http.rest.PagedIterable<ShareFileItem> Lists all sub-directories and files in this directory without their prefix or maxResult in single page.com.azure.core.http.rest.PagedIterable<ShareFileItem> listFilesAndDirectories(ShareListFilesAndDirectoriesOptions options, Duration timeout, com.azure.core.util.Context context) Lists all sub-directories and files in this directory with their prefix or snapshots.com.azure.core.http.rest.PagedIterable<ShareFileItem> listFilesAndDirectories(String prefix, Integer maxResultsPerPage, Duration timeout, com.azure.core.util.Context context) Lists all sub-directories and files in this directory with their prefix or snapshots.com.azure.core.http.rest.PagedIterable<HandleItem> listHandles(Integer maxResultsPerPage, boolean recursive, Duration timeout, com.azure.core.util.Context context) List of open handles on a directory or a file.Moves the directory to another location within the share.com.azure.core.http.rest.Response<ShareDirectoryClient> renameWithResponse(ShareFileRenameOptions options, Duration timeout, com.azure.core.util.Context context) Moves the directory to another location within the share.setMetadata(Map<String, String> metadata) Sets the user-defined metadata to associate to the directory.com.azure.core.http.rest.Response<ShareDirectorySetMetadataInfo> setMetadataWithResponse(Map<String, String> metadata, Duration timeout, com.azure.core.util.Context context) Sets the user-defined metadata to associate to the directory.setProperties(FileSmbProperties smbProperties, String filePermission) Sets the properties of this directory.com.azure.core.http.rest.Response<ShareDirectoryInfo> setPropertiesWithResponse(FileSmbProperties smbProperties, String filePermission, Duration timeout, com.azure.core.util.Context context) Sets the properties of this directory.com.azure.core.http.rest.Response<ShareDirectoryInfo> setPropertiesWithResponse(ShareDirectorySetPropertiesOptions options, Duration timeout, com.azure.core.util.Context context) 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 ShareFileClient that interacts with the specified file.If the file doesn't exist in this directory
ShareFileClient.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 ShareFileClient that interacts with the specified share
-
getSubdirectoryClient
Constructs a ShareDirectoryClient 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 ShareDirectoryClient that interacts with the specified directory
-
exists
Determines if the directory this client represents exists in the cloud.Code Samples
System.out.printf("Exists? %b%n", client.exists());- Returns:
- Flag indicating existence of the directory.
-
existsWithResponse
public com.azure.core.http.rest.Response<Boolean> existsWithResponse(Duration timeout, com.azure.core.util.Context context) Determines if the directory this client represents exists in the cloud.Code Samples
Context context = new Context("Key", "Value"); System.out.printf("Exists? %b%n", client.existsWithResponse(timeout, context).getValue());- Parameters:
timeout- An optional timeout value beyond which aRuntimeExceptionwill be raised.context- Additional context that is passed through the Http pipeline during the service call.- Returns:
- Flag indicating existence of the directory.
-
create
Creates a directory in the file share and returns a response ofShareDirectoryInfoto interact with it.Code Samples
Create the directory
shareDirectoryClient.create(); 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 a directory in the file share if it does not exist.Code Samples
Create the directory
ShareDirectoryClient shareDirectoryClient = createClientWithSASToken(); ShareDirectoryInfo shareDirectoryInfo = shareDirectoryClient.createIfNotExists(); System.out.printf("Last Modified Time:%s", shareDirectoryInfo.getLastModified());For more information, see the Azure Docs.
- Returns:
- A
ShareDirectoryInfothat contains information about the created directory.
-
delete
public void delete()Deletes the directory in the file share. The directory must be empty before it can be deleted.Code Samples
Delete the directory
shareDirectoryClient.delete(); System.out.println("Completed deleting the file.");For more information, see the Azure Docs.
- Throws:
ShareStorageException- If the share doesn't exist
-
deleteWithResponse
public com.azure.core.http.rest.Response<Void> deleteWithResponse(Duration timeout, com.azure.core.util.Context context) Deletes the directory in the file share. The directory must be empty before it can be deleted.Code Samples
Delete the directory
Response<Void> response = shareDirectoryClient.deleteWithResponse(Duration.ofSeconds(1), new Context(key1, value1)); System.out.println("Completed deleting the file with status code: " + response.getStatusCode());For more information, see the Azure Docs.
- Parameters:
timeout- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeExceptionwill be thrown.context- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response that only contains headers and response status code
- Throws:
ShareStorageException- If the share doesn't existRuntimeException- if the operation doesn't complete before the timeout concludes.
-
deleteIfExists
public boolean deleteIfExists()Deletes the directory in the file share if it exists. The directory must be empty before it can be deleted.Code Samples
Delete the directory
ShareDirectoryClient shareDirectoryClient = createClientWithSASToken(); boolean result = shareDirectoryClient.deleteIfExists(); System.out.println("Directory deleted: " + result);For more information, see the Azure Docs.
- Returns:
trueif the directory is successfully deleted,falseif the directory does not exist.
-
deleteIfExistsWithResponse
public com.azure.core.http.rest.Response<Boolean> deleteIfExistsWithResponse(Duration timeout, com.azure.core.util.Context context) Deletes the directory in the file share if it exists. The directory must be empty before it can be deleted.Code Samples
Delete the directory
Response<Boolean> response = shareDirectoryClient.deleteIfExistsWithResponse(Duration.ofSeconds(1), new Context(key1, value1)); if (response.getStatusCode() == 404) { System.out.println("Does not exist."); } else { System.out.printf("Delete completed with status %d%n", response.getStatusCode()); }For more information, see the Azure Docs.
- Parameters:
timeout- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeExceptionwill be thrown.context- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response containing status code and HTTP headers. 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 includes directory metadata, last modified date, is server encrypted, and eTag.Code Samples
Retrieve directory properties
ShareDirectoryProperties response = shareDirectoryClient.getProperties(); System.out.printf("Directory latest modified date is %s.", response.getLastModified());For more information, see the Azure Docs.
- Returns:
- Storage directory properties
-
getPropertiesWithResponse
public com.azure.core.http.rest.Response<ShareDirectoryProperties> getPropertiesWithResponse(Duration timeout, com.azure.core.util.Context context) Retrieves the properties of this directory. The properties includes directory metadata, last modified date, is server encrypted, and eTag.Code Samples
Retrieve directory properties
Response<ShareDirectoryProperties> response = shareDirectoryClient.getPropertiesWithResponse( Duration.ofSeconds(1), new Context(key1, value1)); System.out.printf("Directory latest modified date is %s.", response.getValue().getLastModified());For more information, see the Azure Docs.
- Parameters:
timeout- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeExceptionwill be thrown.context- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response containing the storage directory properties with response status code and headers
- Throws:
RuntimeException- if the operation doesn't complete before the timeout concludes.
-
setMetadata
Sets the user-defined metadata to associate to the directory.If
nullis passed for the metadata it will clear the metadata associated to the directory.Code Samples
Set the metadata to "directory:updatedMetadata"
ShareDirectorySetMetadataInfo response = shareDirectoryClient.setMetadata(Collections.singletonMap("directory", "updatedMetadata")); System.out.printf("Setting the directory metadata completed with updated etag %s", response.getETag());Clear the metadata of the directory
ShareDirectorySetMetadataInfo response = shareDirectoryClient.setMetadata(null); System.out.printf("Cleared metadata.");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:
- The information about the directory
- Throws:
ShareStorageException- If the directory doesn't exist or the metadata contains invalid keys
-
setMetadataWithResponse
public com.azure.core.http.rest.Response<ShareDirectorySetMetadataInfo> setMetadataWithResponse(Map<String, String> metadata, Duration timeout, com.azure.core.util.Context context) Sets the user-defined metadata to associate to the directory.If
nullis passed for the metadata it will clear the metadata associated to the directory.Code Samples
Set the metadata to "directory:updatedMetadata"
Response<ShareDirectorySetMetadataInfo> response = shareDirectoryClient.setMetadataWithResponse(Collections.singletonMap("directory", "updatedMetadata"), Duration.ofSeconds(1), new Context(key1, value1)); System.out.printf("Setting the directory metadata completed with updated etag %d", response.getStatusCode());Clear the metadata of the directory
Response<ShareDirectorySetMetadataInfo> response = shareDirectoryClient.setMetadataWithResponse(null, Duration.ofSeconds(1), new Context(key1, value1)); System.out.printf("Directory latest modified date is %s.", 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 clearedtimeout- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeExceptionwill be thrown.context- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response containing the information about the directory and response status code
- Throws:
ShareStorageException- If the directory doesn't exist or the metadata contains invalid keysRuntimeException- if the operation doesn't complete before the timeout concludes.
-
listFilesAndDirectories
Lists all sub-directories and files in this directory without their prefix or maxResult in single page.Code Samples
List all sub-directories and files in the account
shareDirectoryClient.listFilesAndDirectories().forEach( fileRef -> System.out.printf("Is the resource a directory? %b. The resource name is: %s.", fileRef.isDirectory(), fileRef.getName()) );For more information, see the Azure Docs.
- Returns:
File infoin the storage directory
-
listFilesAndDirectories
public com.azure.core.http.rest.PagedIterable<ShareFileItem> listFilesAndDirectories(String prefix, Integer maxResultsPerPage, Duration timeout, com.azure.core.util.Context context) Lists all sub-directories and files in this directory with their prefix or snapshots.Code Samples
List all sub-directories and files in this directory with "subdir" prefix and return 10 results in the account
shareDirectoryClient.listFilesAndDirectories("subdir", 10, Duration.ofSeconds(1), new Context(key1, value1)).forEach( fileRef -> System.out.printf("Is the resource a directory? %b. The resource name is: %s.", fileRef.isDirectory(), fileRef.getName()) );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. If iterating by page, the page size passed to byPage methods such asContinuablePagedIterable.iterableByPage(int)will be preferred over this value.timeout- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeExceptionwill be thrown.context- Additional context that is passed through the Http pipeline during the service call.- Returns:
File infoin this directory with prefix and max number of return results.- Throws:
RuntimeException- if the operation doesn't complete before the timeout concludes.
-
listHandles
public com.azure.core.http.rest.PagedIterable<HandleItem> listHandles(Integer maxResultsPerPage, boolean recursive, Duration timeout, com.azure.core.util.Context context) List of open handles on a directory or a file.Code Samples
Get 10 handles with recursive call.
Iterable<HandleItem> result = shareDirectoryClient.listHandles(10, true, Duration.ofSeconds(1), new Context(key1, value1)); System.out.printf("Get handles completed with handle id %s", result.iterator().next().getHandleId());For more information, see the Azure Docs.
- Parameters:
maxResultsPerPage- 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.timeout- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeExceptionwill be thrown.context- Additional context that is passed through the Http pipeline during the service call.- Returns:
handlesin the directory that satisfy the requirements- Throws:
RuntimeException- if the operation doesn't complete before the timeout concludes.
-
forceCloseHandle
Closes a handle on the directory at the service. This is intended to be used alongsidelistHandles(Integer, boolean, Duration, Context).Code Samples
Force close handles returned by list handles.
shareDirectoryClient.listHandles(null, true, Duration.ofSeconds(30), Context.NONE).forEach(handleItem -> { shareDirectoryClient.forceCloseHandle(handleItem.getHandleId()); 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:
- Information about the closed handles.
-
forceCloseHandleWithResponse
public com.azure.core.http.rest.Response<CloseHandlesInfo> forceCloseHandleWithResponse(String handleId, Duration timeout, com.azure.core.util.Context context) Closes a handle on the directory at the service. This is intended to be used alongsidelistHandles(Integer, boolean, Duration, Context).Code Samples
Force close handles returned by list handles.
shareDirectoryClient.listHandles(null, true, Duration.ofSeconds(30), Context.NONE).forEach(handleItem -> { Response<CloseHandlesInfo> closeResponse = shareDirectoryClient.forceCloseHandleWithResponse( handleItem.getHandleId(), Duration.ofSeconds(30), Context.NONE); System.out.printf("Closing handle %s on resource %s completed with status code %d%n", handleItem.getHandleId(), handleItem.getPath(), closeResponse.getStatusCode()); });For more information, see the Azure Docs.
- Parameters:
handleId- Handle ID to be clsoed.timeout- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeExceptionwill be thrown.context- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response that contains information about the closed handles, headers and response status code.
-
forceCloseAllHandles
public CloseHandlesInfo forceCloseAllHandles(boolean recursive, Duration timeout, com.azure.core.util.Context context) Closes all handles opened on the directory at the service.Code Samples
Force close all handles recursively.
CloseHandlesInfo closeHandlesInfo = shareDirectoryClient.forceCloseAllHandles(true, Duration.ofSeconds(30), Context.NONE); System.out.printf("Closed %d open handles on the directory%n", closeHandlesInfo.getClosedHandles()); System.out.printf("Failed to close %d open handles on the directory%n", 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.timeout- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeExceptionwill be thrown.context- Additional context that is passed through the Http pipeline during the service call.- Returns:
- Information about the closed handles
-
rename
Moves the directory to another location within the share. For more information see the Azure Docs.Code Samples
ShareDirectoryClient renamedClient = client.rename(destinationPath); System.out.println("Directory Client has been renamed");- Parameters:
destinationPath- Relative path from the share to rename the directory to.- Returns:
- A
ShareDirectoryClientused to interact with the new file created.
-
createSubdirectory
Creates a subdirectory under current directory with specific name and returns a response of ShareDirectoryClient to interact with it.Code Samples
Create the sub directory "subdir"
shareDirectoryClient.createSubdirectory("subdir"); System.out.println("Completed creating the subdirectory.");For more information, see the Azure Docs.
- Parameters:
subdirectoryName- Name of the subdirectory- Returns:
- The 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 specified name if it does not exist.Code Samples
Create the sub directory "subdir"
ShareDirectoryClient subdirectoryClient = shareDirectoryClient.createSubdirectoryIfNotExists("subdir");For more information, see the Azure Docs.
- Parameters:
subdirectoryName- Name of the subdirectory- Returns:
- A
ShareDirectoryClientused to interact with the subdirectory created.
-
deleteSubdirectory
Deletes the subdirectory with specific name in this directory. The directory must be empty before it can be deleted.Code Samples
Delete the subdirectory named "subdir"
shareDirectoryClient.deleteSubdirectory("mysubdirectory"); System.out.println("Complete deleting the subdirectory.");For more information, see the Azure Docs.
- Parameters:
subdirectoryName- Name of the subdirectory- Throws:
ShareStorageException- If the subdirectory doesn't exist, the parent directory does not exist or subdirectory name is an invalid resource name.
-
deleteSubdirectoryWithResponse
public com.azure.core.http.rest.Response<Void> deleteSubdirectoryWithResponse(String subdirectoryName, Duration timeout, com.azure.core.util.Context context) Deletes the subdirectory with specific name in this directory. The directory must be empty before it can be deleted.Code Samples
Delete the subdirectory named "subdir"
Response<Void> response = shareDirectoryClient.deleteSubdirectoryWithResponse("mysubdirectory", Duration.ofSeconds(1), new Context(key1, value1)); System.out.println("Completed deleting the subdirectory with status code: " + response.getStatusCode());For more information, see the Azure Docs.
- Parameters:
subdirectoryName- Name of the subdirectorytimeout- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeExceptionwill be thrown.context- Additional context that is passed through the Http pipeline during the service call.- 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.RuntimeException- if the operation doesn't complete before the timeout concludes.
-
deleteSubdirectoryIfExists
Deletes the subdirectory with specific name in this directory if it exists. The directory must be empty before it can be deleted.Code Samples
Delete the subdirectory named "subdir"
boolean result = shareDirectoryClient.deleteSubdirectoryIfExists("mysubdirectory"); System.out.println("Subdirectory deleted: " + result);For more information, see the Azure Docs.
- Parameters:
subdirectoryName- Name of the subdirectory- Returns:
trueif subdirectory is successfully deleted,falseif subdirectory does not exist.
-
deleteSubdirectoryIfExistsWithResponse
public com.azure.core.http.rest.Response<Boolean> deleteSubdirectoryIfExistsWithResponse(String subdirectoryName, Duration timeout, com.azure.core.util.Context context) Deletes the subdirectory with specific name in this directory if it exists. The directory must be empty before it can be deleted.Code Samples
Delete the subdirectory named "mysubdirectory"
Response<Boolean> response = shareDirectoryClient.deleteSubdirectoryIfExistsWithResponse("mysubdirectory", Duration.ofSeconds(1), new Context(key1, value1)); if (response.getStatusCode() == 404) { System.out.println("Does not exist."); } else { System.out.printf("Delete completed with status %d%n", response.getStatusCode()); }For more information, see the Azure Docs.
- Parameters:
subdirectoryName- Name of the subdirectorytimeout- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeExceptionwill be thrown.context- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response containing status code and HTTP headers. 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"
ShareFileClient response = shareDirectoryClient.createFile("myfile", 1024); System.out.println("Completed creating the file: " + response);For more information, see the Azure Docs.
- Parameters:
fileName- Name of the filemaxSize- Size of the file- Returns:
- The ShareFileClient
- 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"
shareDirectoryClient.deleteFile("myfile"); System.out.println("Completed deleting the file.");For more information, see the Azure Docs.
- Parameters:
fileName- Name of the file- Throws:
ShareStorageException- If the directory doesn't exist or the file doesn't exist or file name is an invalid resource name.
-
deleteFileWithResponse
public com.azure.core.http.rest.Response<Void> deleteFileWithResponse(String fileName, Duration timeout, com.azure.core.util.Context context) Deletes the file with specific name in this directory.Code Samples
Delete the file "filetest"
Response<Void> response = shareDirectoryClient.deleteFileWithResponse("myfile", Duration.ofSeconds(1), new Context(key1, value1)); System.out.println("Completed deleting the file with status code: " + response.getStatusCode());For more information, see the Azure Docs.
- Parameters:
fileName- Name of the filetimeout- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeExceptionwill be thrown.context- Additional context that is passed through the Http pipeline during the service call.- 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.RuntimeException- if the operation doesn't complete before the timeout concludes.
-
deleteFileIfExists
Deletes the file with specific name in this directory if it exists.Code Samples
Delete the file "filetest"
boolean result = shareDirectoryClient.deleteFileIfExists("myfile"); System.out.println("File deleted: " + result);For more information, see the Azure Docs.
- Parameters:
fileName- Name of the file- Returns:
trueif the file is successfully deleted,falseif the file does not exist.
-
deleteFileIfExistsWithResponse
public com.azure.core.http.rest.Response<Boolean> deleteFileIfExistsWithResponse(String fileName, Duration timeout, com.azure.core.util.Context context) Deletes the file with specific name in this directory if it exists.Code Samples
Delete the file "filetest"
Response<Boolean> response = shareDirectoryClient.deleteFileIfExistsWithResponse("myfile", Duration.ofSeconds(1), new Context(key1, value1)); if (response.getStatusCode() == 404) { System.out.println("Does not exist."); } else { System.out.printf("Delete completed with status %d%n", response.getStatusCode()); }For more information, see the Azure Docs.
- Parameters:
fileName- Name of the filetimeout- An optional timeout applied to the operation. If a response is not returned before the timeout concludes aRuntimeExceptionwill be thrown.context- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response containing status code and HTTP headers. If
Response's status code is 202, the file was successfully deleted. If status code is 404, the file does not exist.
-
getDirectoryPath
Get the directory path of the client.Get directory path.
String directoryPath = shareDirectoryClient.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
public com.azure.core.http.HttpPipeline getHttpPipeline()Gets theHttpPipelinepowering this client.- Returns:
- The pipeline.
-