Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ShareDirectoryClient

Package version

A ShareDirectoryClient represents a URL to the Azure Storage directory allowing you to manipulate its files and directories.

Hierarchy

Index

Constructors

constructor

Properties

accountName

accountName: string

Protected credential

credential: Credential

Credential in the pipleline to authenticate requests to the service, such as AnonymousCredential, StorageSharedKeyCredential. Initialized to an AnonymousCredential if not able to retrieve it from the pipeline.

internal

Protected pipeline

pipeline: Pipeline

Request policy pipeline.

internal

Protected storageClientContext

storageClientContext: StorageClientContext

StorageClient is a reference to protocol layer operations entry, which is generated by AutoRest generator.

url

url: string

URL string value.

Accessors

name

  • get name(): string

path

  • get path(): string

shareName

  • get shareName(): string
  • The share name corresponding to this directory client

    Returns string

Methods

create

createFile

createIfNotExists

createSubdirectory

delete

deleteFile

  • Removes the specified file under this directory from the storage account. When a file is successfully deleted, it is immediately removed from the storage account's index and is no longer accessible to clients. The file's data is later removed from the service during garbage collection.

    Delete File will fail with status code 409 (Conflict) and error code SharingViolation if the file is open on an SMB client.

    Delete File is not supported on a share snapshot, which is a read-only copy of a share. An attempt to perform this operation on a share snapshot will fail with 400 (InvalidQueryParameterValue)

    see

    https://docs.microsoft.com/en-us/rest/api/storageservices/delete-file2

    Parameters

    • fileName: string

      Name of the file to delete

    • Default value options: FileDeleteOptions = {}

      Options to File Delete operation.

    Returns Promise<FileDeleteResponse>

    File deletion response data.

deleteIfExists

deleteSubdirectory

exists

  • Returns true if the specified directory exists; false otherwise.

    NOTE: use this function with care since an existing directory might be deleted by other clients or applications. Vice versa new directories might be added by other clients or applications after this function completes.

    Parameters

    Returns Promise<boolean>

forceCloseAllHandles

forceCloseHandle

getDirectoryClient

  • Creates a ShareDirectoryClient object for a sub directory.

    Parameters

    • subDirectoryName: string

      A subdirectory name

    Returns ShareDirectoryClient

    The ShareDirectoryClient object for the given subdirectory name.

    Example usage:

    const directoryClient = shareClient.getDirectoryClient("<directory name>");
    await directoryClient.create();
    console.log("Created directory successfully");

getFileClient

  • Creates a ShareFileClient object.

    Parameters

    • fileName: string

      A file name.

    Returns ShareFileClient

    A new ShareFileClient object for the given file name.

    Example usage:

    const content = "Hello world!"
    
    const fileClient = directoryClient.getFileClient("<file name>");
    
    await fileClient.create(content.length);
    console.log("Created file successfully!");
    
    await fileClient.uploadRange(content, 0, content.length);
    console.log("Updated file successfully!")

getProperties

listFilesAndDirectories

  • Returns an async iterable iterator to list all the files and directories under the specified account.

    .byPage() returns an async iterable iterator to list the files and directories in pages.

    Example using for await syntax:

    let i = 1;
    for await (const entity of directoryClient.listFilesAndDirectories()) {
      if (entity.kind === "directory") {
        console.log(`${i++} - directory\t: ${entity.name}`);
      } else {
        console.log(`${i++} - file\t: ${entity.name}`);
      }
    }

    Example using iter.next():

    let i = 1;
    let iter = directoryClient.listFilesAndDirectories();
    let entity = await iter.next();
    while (!entity.done) {
      if (entity.value.kind === "directory") {
        console.log(`${i++} - directory\t: ${entity.value.name}`);
      } else {
        console.log(`${i++} - file\t: ${entity.value.name}`);
      }
      entity = await iter.next();
    }

    Example using byPage():

    // passing optional maxPageSize in the page settings
    let i = 1;
    for await (const response of directoryClient
      .listFilesAndDirectories()
      .byPage({ maxPageSize: 20 })) {
      for (const fileItem of response.segment.fileItems) {
        console.log(`${i++} - file\t: ${fileItem.name}`);
      }
      for (const dirItem of response.segment.directoryItems) {
        console.log(`${i++} - directory\t: ${dirItem.name}`);
      }
    }

    Example using paging with a marker:

    let i = 1;
    let iterator = directoryClient.listFilesAndDirectories().byPage({ maxPageSize: 3 });
    let response = (await iterator.next()).value;
    
    // Prints 3 file and directory names
    for (const fileItem of response.segment.fileItems) {
      console.log(`${i++} - file\t: ${fileItem.name}`);
    }
    
    for (const dirItem of response.segment.directoryItems) {
      console.log(`${i++} - directory\t: ${dirItem.name}`);
    }
    
    // Gets next marker
    let dirMarker = response.continuationToken;
    
    // Passing next marker as continuationToken
    iterator = directoryClient
      .listFilesAndDirectories()
      .byPage({ continuationToken: dirMarker, maxPageSize: 4 });
    response = (await iterator.next()).value;
    
    // Prints 10 file and directory names
    for (const fileItem of response.segment.fileItems) {
      console.log(`${i++} - file\t: ${fileItem.name}`);
    }
    
    for (const dirItem of response.segment.directoryItems) {
      console.log(`${i++} - directory\t: ${dirItem.name}`);
    }

    Parameters

    Returns PagedAsyncIterableIterator<({ kind: "file" } & FileItem) | ({ kind: "directory" } & DirectoryItem), DirectoryListFilesAndDirectoriesSegmentResponse>

    An asyncIterableIterator that supports paging.

listHandles

  • Returns an async iterable iterator to list all the handles. under the specified account.

    .byPage() returns an async iterable iterator to list the handles in pages.

    Example using for await syntax:

    let i = 1;
    let iter = dirClient.listHandles();
    for await (const handle of iter) {
      console.log(`Handle ${i++}: ${handle.path}, opened time ${handle.openTime}, clientIp ${handle.clientIp}`);
    }

    Example using iter.next():

    let i = 1;
    let iter = dirClient.listHandles();
    let handleItem = await iter.next();
    while (!handleItem.done) {
      console.log(`Handle ${i++}: ${handleItem.value.path}, opened time ${handleItem.value.openTime}, clientIp ${handleItem.value.clientIp}`);
      handleItem = await iter.next();
    }

    Example using byPage():

    // passing optional maxPageSize in the page settings
    let i = 1;
    for await (const response of dirClient.listHandles({ recursive: true }).byPage({ maxPageSize: 20 })) {
      if (response.handleList) {
        for (const handle of response.handleList) {
          console.log(`Handle ${i++}: ${handle.path}, opened time ${handle.openTime}, clientIp ${handle.clientIp}`);
        }
      }
    }

    Example using paging with a marker:

    let i = 1;
    let iterator = dirClient.listHandles().byPage({ maxPageSize: 2 });
    let response = await iterator.next();
    
    // Prints 2 handles
    if (response.value.handleList) {
      for (const handle of response.value.handleList) {
        console.log(`Handle ${i++}: ${handle.path}, opened time ${handle.openTime}, clientIp ${handle.clientIp}`);
      }
    }
    
    // Gets next marker
    let marker = response.value.continuationToken;
    
    // Passing next marker as continuationToken
    console.log(`    continuation`);
    iterator = dirClient.listHandles().byPage({ continuationToken: marker, maxPageSize: 10 });
    response = await iterator.next();
    
    // Prints 2 more handles assuming you have more than four directory/files opened
    if (!response.done && response.value.handleList) {
      for (const handle of response.value.handleList) {
        console.log(`Handle ${i++}: ${handle.path}, opened time ${handle.openTime}, clientIp ${handle.clientIp}`);
      }
    }

    Parameters

    • Default value options: DirectoryListHandlesOptions = {}

      Options to list handles operation.

      An asyncIterableIterator that supports paging.

    Returns PagedAsyncIterableIterator<HandleItem, DirectoryListHandlesResponse>

setMetadata

setProperties

Generated using TypeDoc