你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
ShareDirectoryClient Class
- java.
lang. Object - com.
azure. storage. file. share. ShareDirectoryClient
- com.
public class ShareDirectoryClient
This class provides a client that contains all the operations for interacting with directory in Azure Storage File Service. Operations allowed by the client are creating, deleting and listing subdirectory and file, retrieving properties, setting metadata and list or force close handles of the directory or file.
Instantiating an Synchronous Directory Client
ShareDirectoryClient client = new ShareFileClientBuilder()
.connectionString("${connectionString}")
.endpoint("${endpoint}")
.buildDirectoryClient();
View ShareFileClientBuilder for additional ways to construct the client.
Method Summary
Methods inherited from java.lang.Object
Method Details
create
public ShareDirectoryInfo create()
Creates a directory in the file share and returns a response of ShareDirectoryInfo to 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:
createFile
public ShareFileClient 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.
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:
Returns:
createFileWithResponse
public Response
Creates a file in this directory with specific name and returns a response of ShareDirectoryInfo to interact with it.
Code Samples
Create the file named "myFile"
ShareFileHttpHeaders httpHeaders = new ShareFileHttpHeaders()
.setContentType("text/html")
.setContentEncoding("gzip")
.setContentLanguage("en")
.setCacheControl("no-transform")
.setContentDisposition("attachment");
FileSmbProperties smbProperties = new FileSmbProperties()
.setNtfsFileAttributes(EnumSet.of(NtfsFileAttributes.READ_ONLY))
.setFileCreationTime(OffsetDateTime.now())
.setFileLastWriteTime(OffsetDateTime.now())
.setFilePermissionKey("filePermissionKey");
String filePermission = "filePermission";
// NOTE: filePermission and filePermissionKey should never be both set
ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
Response<ShareFileClient> response = shareDirectoryClient.createFileWithResponse("myFile", 1024,
httpHeaders, smbProperties, filePermission, Collections.singletonMap("directory", "metadata"),
requestConditions, Duration.ofSeconds(1), new Context(key1, value1));
System.out.println("Completed creating the file with status code: " + response.getStatusCode());
For more information, see the Azure Docs.
Parameters:
Returns:
createFileWithResponse
public Response
Creates a file in this directory with specific name and returns a response of ShareDirectoryInfo to interact with it.
Code Samples
Create the file named "myFile"
ShareFileHttpHeaders httpHeaders = new ShareFileHttpHeaders()
.setContentType("text/html")
.setContentEncoding("gzip")
.setContentLanguage("en")
.setCacheControl("no-transform")
.setContentDisposition("attachment");
FileSmbProperties smbProperties = new FileSmbProperties()
.setNtfsFileAttributes(EnumSet.of(NtfsFileAttributes.READ_ONLY))
.setFileCreationTime(OffsetDateTime.now())
.setFileLastWriteTime(OffsetDateTime.now())
.setFilePermissionKey("filePermissionKey");
String filePermission = "filePermission";
// NOTE: filePermission and filePermissionKey should never be both set
Response<ShareFileClient> response = shareDirectoryClient.createFileWithResponse("myFile", 1024,
httpHeaders, smbProperties, filePermission, Collections.singletonMap("directory", "metadata"),
Duration.ofSeconds(1), new Context(key1, value1));
System.out.println("Completed creating the file with status code: " + response.getStatusCode());
For more information, see the Azure Docs.
Parameters:
Returns:
createIfNotExists
public ShareDirectoryInfo 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:
createIfNotExistsWithResponse
public Response
Creates a directory in the file share if it does not exist.
Code Samples
Create the directory
ShareDirectoryClient directoryClient = createClientWithSASToken();
FileSmbProperties smbProperties = new FileSmbProperties();
String filePermission = "filePermission";
ShareDirectoryCreateOptions options = new ShareDirectoryCreateOptions().setSmbProperties(smbProperties)
.setFilePermission(filePermission).setMetadata(Collections.singletonMap("directory", "metadata"));
Response<ShareDirectoryInfo> response = directoryClient.createIfNotExistsWithResponse(options,
Duration.ofSeconds(1), new Context(key1, value1));
if (response.getStatusCode() == 409) {
System.out.println("Already existed.");
} else {
System.out.printf("Create completed with status %d%n", response.getStatusCode());
}
For more information, see the Azure Docs.
Parameters:
Returns:
createSubdirectory
public ShareDirectoryClient createSubdirectory(String subdirectoryName)
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:
Returns:
createSubdirectoryIfNotExists
public ShareDirectoryClient createSubdirectoryIfNotExists(String subdirectoryName)
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:
Returns:
createSubdirectoryIfNotExistsWithResponse
public Response
Creates a subdirectory under current directory with specific name and metadata if it does not exist.
Code Samples
Create the subdirectory named "subdir", with metadata
FileSmbProperties smbProperties = new FileSmbProperties();
String filePermission = "filePermission";
ShareDirectoryCreateOptions options = new ShareDirectoryCreateOptions().setSmbProperties(smbProperties)
.setFilePermission(filePermission).setMetadata(Collections.singletonMap("directory", "metadata"));
Response<ShareDirectoryClient> response = shareDirectoryClient
.createSubdirectoryIfNotExistsWithResponse("subdir", options, Duration.ofSeconds(1),
new Context(key1, value1));
if (response.getStatusCode() == 409) {
System.out.println("Already existed.");
} else {
System.out.printf("Create completed with status %d%n", response.getStatusCode());
}
For more information, see the Azure Docs.
Parameters:
Returns:
createSubdirectoryWithResponse
public Response
Creates a subdirectory under current directory with specific name , metadata and returns a response of ShareDirectoryClient to interact with it.
Code Samples
Create the subdirectory named "subdir", with metadata
FileSmbProperties smbProperties = new FileSmbProperties();
String filePermission = "filePermission";
Response<ShareDirectoryClient> response = shareDirectoryClient.createSubdirectoryWithResponse("subdir",
smbProperties, filePermission, Collections.singletonMap("directory", "metadata"),
Duration.ofSeconds(1), new Context(key1, value1));
System.out.printf("Creating the sub directory completed with status code %d", response.getStatusCode());
For more information, see the Azure Docs.
Parameters:
Returns:
createWithResponse
public Response
Creates a directory in the file share and returns a response of ShareDirectoryInfo to interact with it.
Code Samples
Create the directory
FileSmbProperties smbProperties = new FileSmbProperties();
String filePermission = "filePermission";
Response<ShareDirectoryInfo> response = shareDirectoryClient.createWithResponse(smbProperties, filePermission,
Collections.singletonMap("directory", "metadata"), Duration.ofSeconds(1), new Context(key1, value1));
System.out.println("Completed creating the directory with status code: " + response.getStatusCode());
For more information, see the Azure Docs.
Parameters:
Returns:
createWithResponse
public Response
Creates a directory in the file share and returns a response of ShareDirectoryInfo to interact with it.
Code Samples
Create the directory
FileSmbProperties smbProperties = new FileSmbProperties();
String filePermission = "filePermission";
ShareDirectoryCreateOptions options = new ShareDirectoryCreateOptions().setSmbProperties(smbProperties)
.setFilePermission(filePermission).setFilePermissionFormat(FilePermissionFormat.BINARY)
.setMetadata(Collections.singletonMap("directory", "metadata"));
Response<ShareDirectoryInfo> response = shareDirectoryClient.createWithResponse(options, Duration.ofSeconds(1),
new Context(key1, value1));
System.out.println("Completed creating the directory with status code: " + response.getStatusCode());
For more information, see the Azure Docs.
Parameters:
Returns:
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.
deleteFile
public void deleteFile(String fileName)
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:
deleteFileIfExists
public boolean deleteFileIfExists(String fileName)
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:
Returns:
true
if the file is successfully deleted, false
if the file does not exist.deleteFileIfExistsWithResponse
public Response
Deletes the file with specific name in this directory if it exists.
Code Samples
Delete the file "filetest"
ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
Response<Boolean> fileResponse = shareDirectoryClient.deleteFileIfExistsWithResponse("myfile", requestConditions,
Duration.ofSeconds(1), new Context(key1, value1));
if (fileResponse.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:
Returns:
deleteFileIfExistsWithResponse
public Response
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:
Returns:
deleteFileWithResponse
public Response
Deletes the file with specific name in this directory.
Code Samples
Delete the file "filetest"
ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
Response<Void> response = shareDirectoryClient.deleteFileWithResponse("myfile", requestConditions,
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:
Returns:
deleteFileWithResponse
public Response
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:
Returns:
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:
true
if the directory is successfully deleted, false
if the directory does not exist.deleteIfExistsWithResponse
public Response
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:
Returns:
deleteSubdirectory
public void deleteSubdirectory(String subdirectoryName)
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:
deleteSubdirectoryIfExists
public boolean deleteSubdirectoryIfExists(String subdirectoryName)
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:
Returns:
true
if subdirectory is successfully deleted, false
if subdirectory does not exist.deleteSubdirectoryIfExistsWithResponse
public Response
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:
Returns:
deleteSubdirectoryWithResponse
public Response
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:
Returns:
deleteWithResponse
public Response
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:
Returns:
exists
public Boolean exists()
Determines if the directory this client represents exists in the cloud.
Code Samples
System.out.printf("Exists? %b%n", client.exists());
Returns:
existsWithResponse
public Response
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:
Returns:
forceCloseAllHandles
public CloseHandlesInfo forceCloseAllHandles(boolean recursive, Duration timeout, 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:
Returns:
forceCloseHandle
public CloseHandlesInfo forceCloseHandle(String handleId)
Closes a handle on the directory at the service. This is intended to be used alongside listHandles(Integer maxResultsPerPage, boolean recursive, Duration timeout, Context 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:
Returns:
forceCloseHandleWithResponse
public Response
Closes a handle on the directory at the service. This is intended to be used alongside listHandles(Integer maxResultsPerPage, boolean recursive, Duration timeout, Context 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:
Returns:
generateSas
public String generateSas(ShareServiceSasSignatureValues shareServiceSasSignatureValues)
Generates a service SAS for the directory using the specified ShareServiceSasSignatureValues
Note : The client must be authenticated via StorageSharedKeyCredential
See ShareServiceSasSignatureValues for more information on how to construct a service SAS.
Code Samples
OffsetDateTime expiryTime = OffsetDateTime.now().plusDays(1);
ShareFileSasPermission permission = new ShareFileSasPermission().setReadPermission(true);
ShareServiceSasSignatureValues values = new ShareServiceSasSignatureValues(expiryTime, permission)
.setStartTime(OffsetDateTime.now());
shareDirectoryClient.generateSas(values); // Client must be authenticated via StorageSharedKeyCredential
Parameters:
Returns:
String
representing the SAS query parameters.generateSas
public String generateSas(ShareServiceSasSignatureValues shareServiceSasSignatureValues, Context context)
Generates a service SAS for the directory using the specified ShareServiceSasSignatureValues
Note : The client must be authenticated via StorageSharedKeyCredential
See ShareServiceSasSignatureValues for more information on how to construct a service SAS.
Code Samples
OffsetDateTime expiryTime = OffsetDateTime.now().plusDays(1);
ShareFileSasPermission permission = new ShareFileSasPermission().setReadPermission(true);
ShareServiceSasSignatureValues values = new ShareServiceSasSignatureValues(expiryTime, permission)
.setStartTime(OffsetDateTime.now());
// Client must be authenticated via StorageSharedKeyCredential
shareDirectoryClient.generateSas(values, new Context("key", "value"));
Parameters:
Returns:
String
representing the SAS query parameters.generateSas
public String generateSas(ShareServiceSasSignatureValues shareServiceSasSignatureValues, Consumer
Generates a service SAS for the directory using the specified ShareServiceSasSignatureValues
Note : The client must be authenticated via StorageSharedKeyCredential
See ShareServiceSasSignatureValues for more information on how to construct a service SAS.
Parameters:
Returns:
String
representing the SAS query parameters.getAccountName
public String getAccountName()
Get associated account name.
Returns:
getDirectoryPath
public String 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:
getDirectoryUrl
public String getDirectoryUrl()
Get the url of the storage directory client.
Returns:
getFileClient
public ShareFileClient getFileClient(String fileName)
Constructs a ShareFileClient that interacts with the specified file.
If the file doesn't exist in this directory create(long maxSize) create} in the client will need to be called before interaction with the file can happen.
Parameters:
Returns:
getHttpPipeline
public HttpPipeline getHttpPipeline()
Gets the HttpPipeline powering this client.
Returns:
getProperties
public ShareDirectoryProperties 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:
getPropertiesWithResponse
public Response
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:
Returns:
getServiceVersion
public ShareServiceVersion getServiceVersion()
Gets the service version the client is using.
Returns:
getShareName
public String getShareName()
Get the share name of directory client.
Get the share name.
String shareName = directoryAsyncClient.getShareName();
System.out.println("The share name of the directory is " + shareName);
Returns:
getShareSnapshotId
public String getShareSnapshotId()
Get snapshot id which attached to ShareDirectoryClient. Return null
if no snapshot id attached.
Code Samples
Get the share snapshot id.
OffsetDateTime currentTime = OffsetDateTime.of(LocalDateTime.now(), ZoneOffset.UTC);
ShareDirectoryClient shareDirectoryClient = new ShareFileClientBuilder()
.endpoint("https://${accountName}.file.core.windows.net")
.sasToken("${SASToken}")
.shareName("myshare")
.resourcePath("mydirectory")
.snapshot(currentTime.toString())
.buildDirectoryClient();
System.out.printf("Snapshot ID: %s%n", shareDirectoryClient.getShareSnapshotId());
Returns:
DateTime
value that identifies the share snapshot to its base
share.getSubdirectoryClient
public ShareDirectoryClient getSubdirectoryClient(String subdirectoryName)
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:
Returns:
listFilesAndDirectories
public PagedIterable
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:
listFilesAndDirectories
public PagedIterable
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(new ShareListFilesAndDirectoriesOptions()
.setPrefix("subdir").setMaxResultsPerPage(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:
Returns:
listFilesAndDirectories
public PagedIterable
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:
Returns:
listHandles
public PagedIterable
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:
Returns:
rename
public ShareDirectoryClient rename(String destinationPath)
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:
Returns:
renameWithResponse
public Response
Moves the directory to another location within the share. For more information see the Azure Docs.
Code Samples
FileSmbProperties smbProperties = new FileSmbProperties()
.setNtfsFileAttributes(EnumSet.of(NtfsFileAttributes.READ_ONLY))
.setFileCreationTime(OffsetDateTime.now())
.setFileLastWriteTime(OffsetDateTime.now())
.setFilePermissionKey("filePermissionKey");
ShareFileRenameOptions options = new ShareFileRenameOptions(destinationPath)
.setDestinationRequestConditions(new ShareRequestConditions().setLeaseId(leaseId))
.setSourceRequestConditions(new ShareRequestConditions().setLeaseId(leaseId))
.setIgnoreReadOnly(false)
.setReplaceIfExists(false)
.setFilePermission("filePermission")
.setSmbProperties(smbProperties);
ShareDirectoryClient newRenamedClient = client.renameWithResponse(options, timeout,
new Context(key1, value1)).getValue();
System.out.println("Directory Client has been renamed");
Parameters:
Returns:
setMetadata
public ShareDirectorySetMetadataInfo setMetadata(Map
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"
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:
Returns:
setMetadataWithResponse
public Response
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"
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:
Returns:
setProperties
public ShareDirectoryInfo setProperties(FileSmbProperties smbProperties, String filePermission)
Sets the properties of this directory. The properties include the file SMB properties and the file permission.
Code Samples
Set directory properties
FileSmbProperties smbProperties = new FileSmbProperties();
String filePermission = "filePermission";
ShareDirectoryInfo response = shareDirectoryClient.setProperties(smbProperties, filePermission);
System.out.printf("Directory latest modified date is %s.", response.getLastModified());
For more information, see the Azure Docs.
Parameters:
Returns:
setPropertiesWithResponse
public Response
Sets the properties of this directory. The properties include the file SMB properties and the file permission.
Code Samples
Set directory properties
FileSmbProperties smbProperties = new FileSmbProperties();
String filePermission = "filePermission";
Response<ShareDirectoryInfo> response = shareDirectoryClient.setPropertiesWithResponse(smbProperties,
filePermission, 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:
Returns:
setPropertiesWithResponse
public Response
Sets the properties of this directory. The properties include the file SMB properties and the file permission.
Code Samples
Set directory properties
ShareDirectorySetPropertiesOptions options = new ShareDirectorySetPropertiesOptions();
options.setSmbProperties(new FileSmbProperties());
options.setFilePermissions(new ShareFilePermission().setPermission("filePermission")
.setPermissionFormat(FilePermissionFormat.BINARY));
Response<ShareDirectoryInfo> response2 = shareDirectoryClient.setPropertiesWithResponse(options,
Duration.ofSeconds(1), new Context(key1, value1));
System.out.printf("Directory latest modified date is %s.", response2.getValue().getLastModified());
For more information, see the Azure Docs.
Parameters:
Returns: