共用方式為


ShareDirectoryClient class

ShareDirectoryClient 代表 Azure 記憶體目錄的 URL,可讓您作其檔案和目錄。

Extends

StorageClient

建構函式

ShareDirectoryClient(string, Credential | TokenCredential, ShareClientOptions)

建立 DirectoryClient 的實例。

ShareDirectoryClient(string, Pipeline, ShareClientConfig)

建立 DirectoryClient 的實例。

屬性

name

目錄的名稱

path

目錄的完整路徑

shareName

對應至此目錄客戶端的共享名稱

繼承的屬性

accountName
url

URL 字串值。

方法

create(DirectoryCreateOptions)

在指定的共享或父目錄下建立新目錄。

請參閱 https://learn.microsoft.com/rest/api/storageservices/create-directory

createFile(string, number, FileCreateOptions)

建立新的檔案,或取代此目錄下的檔案。 請注意,它只會初始化沒有內容的檔案。

請參閱 https://learn.microsoft.com/rest/api/storageservices/create-file

createIfNotExists(DirectoryCreateOptions)

如果指定的共享或父目錄不存在,請建立新目錄。 如果目錄已經存在,則不會修改它。

請參閱 https://learn.microsoft.com/rest/api/storageservices/create-directory

createSubdirectory(string, DirectoryCreateOptions)

在此目錄下建立新的子目錄。

請參閱 https://learn.microsoft.com/rest/api/storageservices/create-directory

delete(DirectoryDeleteOptions)

拿掉指定的空白目錄。 請注意,目錄必須空白,才能刪除目錄。

請參閱 https://learn.microsoft.com/rest/api/storageservices/delete-directory

deleteFile(string, FileDeleteOptions)

從記憶體帳戶移除此目錄下的指定檔案。 成功刪除檔案時,它會立即從記憶體帳戶的索引中移除,且客戶端無法再存取。 檔案的數據稍後會在垃圾收集期間從服務中移除。

如果檔案在SMB用戶端上開啟,刪除檔案將會失敗,狀態代碼為409(衝突)和錯誤碼SharingViolation。

共用快照集不支援刪除檔案,這是共用的唯讀複本。 嘗試在共用快照集上執行這項作業將會失敗,並產生 400 (InvalidQueryParameterValue)

請參閱 https://learn.microsoft.com/rest/api/storageservices/delete-file2

deleteIfExists(DirectoryDeleteOptions)

如果存在,則移除指定的空白目錄。 請注意,目錄必須空白,才能刪除目錄。

請參閱 https://learn.microsoft.com/rest/api/storageservices/delete-directory

deleteSubdirectory(string, DirectoryDeleteOptions)

拿掉這個目錄下指定的空白子目錄。 請注意,目錄必須空白,才能刪除目錄。

請參閱 https://learn.microsoft.com/rest/api/storageservices/delete-directory

exists(DirectoryExistsOptions)

如果指定的目錄存在,則傳回 true;否則為 false。

注意:請小心使用此函式,因為現有的目錄可能會由其他用戶端或應用程式刪除。 反之亦然,此函式完成後,其他用戶端或應用程式可能會新增新的目錄。

forceCloseAllHandles(DirectoryForceCloseHandlesSegmentOptions)

強制關閉目錄的所有句柄。

請參閱 https://learn.microsoft.com/rest/api/storageservices/force-close-handles

forceCloseHandle(string, DirectoryForceCloseHandlesOptions)

強制關閉目錄的特定句柄。

請參閱 https://learn.microsoft.com/rest/api/storageservices/force-close-handles

getDirectoryClient(string)

建立子目錄的 ShareDirectoryClient 物件。

getFileClient(string)

建立 ShareFileClient 物件。

getProperties(DirectoryGetPropertiesOptions)

傳回指定目錄的所有系統屬性,也可用來檢查目錄是否存在。 傳回的數據不包含目錄中或任何子目錄中的檔案。

請參閱 https://learn.microsoft.com/rest/api/storageservices/get-directory-properties

listFilesAndDirectories(DirectoryListFilesAndDirectoriesOptions)

傳回異步反覆運算器,以列出指定帳戶下的所有檔案和目錄。

.byPage() 會傳回異步可反覆運算器,以列出頁面中的檔案和目錄。

使用 for await 語法的範例:

import { StorageSharedKeyCredential, ShareServiceClient } from "@azure/storage-file-share";

const account = "<account>";
const accountKey = "<accountkey>";

const credential = new StorageSharedKeyCredential(account, accountKey);
const serviceClient = new ShareServiceClient(
  `https://${account}.file.core.windows.net`,
  credential,
);

const shareName = "<share name>";
const directoryName = "<directory name>";
const directoryClient = serviceClient.getShareClient(shareName).getDirectoryClient(directoryName);

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

使用 iter.next()的範例:

import { StorageSharedKeyCredential, ShareServiceClient } from "@azure/storage-file-share";

const account = "<account>";
const accountKey = "<accountkey>";

const credential = new StorageSharedKeyCredential(account, accountKey);
const serviceClient = new ShareServiceClient(
  `https://${account}.file.core.windows.net`,
  credential,
);

const shareName = "<share name>";
const directoryName = "<directory name>";
const directoryClient = serviceClient.getShareClient(shareName).getDirectoryClient(directoryName);

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

使用 byPage()的範例:

import { StorageSharedKeyCredential, ShareServiceClient } from "@azure/storage-file-share";

const account = "<account>";
const accountKey = "<accountkey>";

const credential = new StorageSharedKeyCredential(account, accountKey);
const serviceClient = new ShareServiceClient(
  `https://${account}.file.core.windows.net`,
  credential,
);

const shareName = "<share name>";
const directoryName = "<directory name>";
const directoryClient = serviceClient.getShareClient(shareName).getDirectoryClient(directoryName);

let i = 1;
for await (const response of directoryClient
  .listFilesAndDirectories()
  .byPage({ maxPageSize: 20 })) {
  console.log(`Page ${i++}:`);
  for (const item of response.segment.directoryItems) {
    console.log(`\tdirectory: ${item.name}`);
  }
  for (const item of response.segment.fileItems) {
    console.log(`\tfile: ${item.name}`);
  }
}

使用分頁搭配標記的範例:

import { StorageSharedKeyCredential, ShareServiceClient } from "@azure/storage-file-share";

const account = "<account>";
const accountKey = "<accountkey>";

const credential = new StorageSharedKeyCredential(account, accountKey);
const serviceClient = new ShareServiceClient(
  `https://${account}.file.core.windows.net`,
  credential,
);

const shareName = "<share name>";
const directoryName = "<directory name>";
const directoryClient = serviceClient.getShareClient(shareName).getDirectoryClient(directoryName);

let iterator = directoryClient.listFilesAndDirectories().byPage({ maxPageSize: 2 });
let response = (await iterator.next()).value;

for await (const item of response.segment.directoryItems) {
  console.log(`\tdirectory: ${item.name}`);
}

for await (const item of response.segment.fileItems) {
  console.log(`\tfile: ${item.name}`);
}

// Gets next marker
let marker = response.continuationToken;

// Passing next marker as continuationToken
iterator = directoryClient
  .listFilesAndDirectories()
  .byPage({ continuationToken: marker, maxPageSize: 10 });
response = (await iterator.next()).value;

for await (const item of response.segment.directoryItems) {
  console.log(`\tdirectory: ${item.name}`);
}

for await (const item of response.segment.fileItems) {
  console.log(`\tfile: ${item.name}`);
}
listHandles(DirectoryListHandlesOptions)

傳回異步反覆運算器以列出所有句柄。 在指定的帳戶下。

.byPage() 會傳回異步反覆運算器,以列出頁面中的句柄。

使用 for await 語法的範例:

import { StorageSharedKeyCredential, ShareServiceClient } from "@azure/storage-file-share";

const account = "<account>";
const accountKey = "<accountkey>";

const credential = new StorageSharedKeyCredential(account, accountKey);
const serviceClient = new ShareServiceClient(
  `https://${account}.file.core.windows.net`,
  credential,
);

const shareName = "<share name>";
const directoryName = "<directory name>";
const directoryClient = serviceClient.getShareClient(shareName).getDirectoryClient(directoryName);

for await (const handle of directoryClient.listHandles()) {
  console.log(`Handle: ${handle.handleId}`);
}

使用 iter.next()的範例:

import { StorageSharedKeyCredential, ShareServiceClient } from "@azure/storage-file-share";

const account = "<account>";
const accountKey = "<accountkey>";

const credential = new StorageSharedKeyCredential(account, accountKey);
const serviceClient = new ShareServiceClient(
  `https://${account}.file.core.windows.net`,
  credential,
);

const shareName = "<share name>";
const directoryName = "<directory name>";
const directoryClient = serviceClient.getShareClient(shareName).getDirectoryClient(directoryName);

const handleIter = directoryClient.listHandles();
let { value, done } = await handleIter.next();
while (!done) {
  console.log(`Handle: ${value.handleId}`);
  ({ value, done } = await handleIter.next());
}

使用 byPage()的範例:

import { StorageSharedKeyCredential, ShareServiceClient } from "@azure/storage-file-share";

const account = "<account>";
const accountKey = "<accountkey>";

const credential = new StorageSharedKeyCredential(account, accountKey);
const serviceClient = new ShareServiceClient(
  `https://${account}.file.core.windows.net`,
  credential,
);

const shareName = "<share name>";
const directoryName = "<directory name>";
const directoryClient = serviceClient.getShareClient(shareName).getDirectoryClient(directoryName);

let i = 1;
for await (const response of directoryClient.listHandles().byPage({ maxPageSize: 20 })) {
  console.log(`Page ${i++}:`);
  for (const handle of response.handleList || []) {
    console.log(`\thandle: ${handle.handleId}`);
  }
}

使用分頁搭配標記的範例:

import { StorageSharedKeyCredential, ShareServiceClient } from "@azure/storage-file-share";

const account = "<account>";
const accountKey = "<accountkey>";

const credential = new StorageSharedKeyCredential(account, accountKey);
const serviceClient = new ShareServiceClient(
  `https://${account}.file.core.windows.net`,
  credential,
);

const shareName = "<share name>";
const directoryName = "<directory name>";
const directoryClient = serviceClient.getShareClient(shareName).getDirectoryClient(directoryName);

let iterator = directoryClient.listHandles().byPage({ maxPageSize: 2 });
let response = (await iterator.next()).value;

for await (const handle of response.handleList || []) {
  console.log(`\thandle: ${handle.handleId}`);
}

// Gets next marker
let marker = response.continuationToken;

// Passing next marker as continuationToken
iterator = directoryClient.listHandles().byPage({ continuationToken: marker, maxPageSize: 10 });
response = (await iterator.next()).value;

for await (const handle of response.handleList || []) {
  console.log(`\thandle: ${handle.handleId}`);
}
rename(string, DirectoryRenameOptions)

重新命名目錄。 此 API 僅支援在相同共用中重新命名目錄。

setMetadata(Metadata, DirectorySetMetadataOptions)

更新指定目錄的使用者定義元數據。

請參閱 https://learn.microsoft.com/rest/api/storageservices/set-directory-metadata

setProperties(DirectoryProperties)

設定目錄上的屬性。

請參閱 https://learn.microsoft.com/rest/api/storageservices/set-directory-properties

建構函式詳細資料

ShareDirectoryClient(string, Credential | TokenCredential, ShareClientOptions)

建立 DirectoryClient 的實例。

new ShareDirectoryClient(url: string, credential?: Credential | TokenCredential, options?: ShareClientOptions)

參數

url

string

指向 Azure 記憶體檔案目錄的 URL 字串,例如 「https://myaccount.file.core.windows.net/myshare/mydirectory"。 如果使用 AnonymousCredential,則可以附加 SAS,例如 “https://myaccount.file.core.windows.net/myshare/mydirectory?sasString"。 此方法接受指向目錄的編碼 URL 或非編碼 URL。 編碼的 URL 字串不會逸出兩次,只會逸出 URL 路徑中的特殊字元。 不過,如果目錄名稱包含 %,則必須在URL中編碼目錄名稱。 例如名為 「mydir%」 的目錄,URL 應該是 「https://myaccount.file.core.windows.net/myshare/mydir%25"。

credential

Credential | TokenCredential

例如 AnonymousCredential 或 StorageSharedKeyCredential。 如果未指定,則會使用 AnonymousCredential。

options
ShareClientOptions

Optional. 設定 HTTP 管線的選項。

ShareDirectoryClient(string, Pipeline, ShareClientConfig)

建立 DirectoryClient 的實例。

new ShareDirectoryClient(url: string, pipeline: Pipeline, options?: ShareClientConfig)

參數

url

string

指向 Azure 記憶體檔案目錄的 URL 字串,例如 「https://myaccount.file.core.windows.net/myshare/mydirectory"。 如果使用 AnonymousCredential,則可以附加 SAS,例如 “https://myaccount.file.core.windows.net/myshare/mydirectory?sasString"。 此方法接受指向目錄的編碼 URL 或非編碼 URL。 編碼的 URL 字串不會逸出兩次,只會逸出 URL 路徑中的特殊字元。 不過,如果目錄名稱包含 %,則必須在URL中編碼目錄名稱。 例如名為 「mydir%」 的目錄,URL 應該是 「https://myaccount.file.core.windows.net/myshare/mydir%25"。

pipeline
Pipeline

呼叫 newPipeline() 以建立預設管線,或提供自定義管線。

屬性詳細資料

name

目錄的名稱

string name

屬性值

string

path

目錄的完整路徑

string path

屬性值

string

shareName

對應至此目錄客戶端的共享名稱

string shareName

屬性值

string

繼承的屬性詳細資料

accountName

accountName: string

屬性值

string

繼承自 StorageClient.accountName

url

URL 字串值。

url: string

屬性值

string

繼承自 StorageClient.url

方法詳細資料

create(DirectoryCreateOptions)

在指定的共享或父目錄下建立新目錄。

請參閱 https://learn.microsoft.com/rest/api/storageservices/create-directory

function create(options?: DirectoryCreateOptions): Promise<DirectoryCreateResponse>

參數

options
DirectoryCreateOptions

目錄建立作業的選項。

傳回

目錄作業的回應數據。

createFile(string, number, FileCreateOptions)

建立新的檔案,或取代此目錄下的檔案。 請注意,它只會初始化沒有內容的檔案。

請參閱 https://learn.microsoft.com/rest/api/storageservices/create-file

function createFile(fileName: string, size: number, options?: FileCreateOptions): Promise<{ fileClient: ShareFileClient, fileCreateResponse: FileCreateResponse }>

參數

fileName

string

size

number

指定檔案的大小上限,最多為 4 TB。

options
FileCreateOptions

檔案建立作業的選項。

傳回

Promise<{ fileClient: ShareFileClient, fileCreateResponse: FileCreateResponse }>

檔案建立回應數據和對應的檔案用戶端。

createIfNotExists(DirectoryCreateOptions)

如果指定的共享或父目錄不存在,請建立新目錄。 如果目錄已經存在,則不會修改它。

請參閱 https://learn.microsoft.com/rest/api/storageservices/create-directory

function createIfNotExists(options?: DirectoryCreateOptions): Promise<DirectoryCreateIfNotExistsResponse>

參數

傳回

createSubdirectory(string, DirectoryCreateOptions)

在此目錄下建立新的子目錄。

請參閱 https://learn.microsoft.com/rest/api/storageservices/create-directory

function createSubdirectory(directoryName: string, options?: DirectoryCreateOptions): Promise<{ directoryClient: ShareDirectoryClient, directoryCreateResponse: DirectoryCreateResponse }>

參數

directoryName

string

options
DirectoryCreateOptions

目錄建立作業的選項。

傳回

Promise<{ directoryClient: ShareDirectoryClient, directoryCreateResponse: DirectoryCreateResponse }>

目錄會建立回應數據和對應的 DirectoryClient 實例。

delete(DirectoryDeleteOptions)

拿掉指定的空白目錄。 請注意,目錄必須空白,才能刪除目錄。

請參閱 https://learn.microsoft.com/rest/api/storageservices/delete-directory

function delete(options?: DirectoryDeleteOptions): Promise<DirectoryDeleteResponse>

參數

options
DirectoryDeleteOptions

目錄刪除作業的選項。

傳回

目錄刪除作業的回應數據。

deleteFile(string, FileDeleteOptions)

從記憶體帳戶移除此目錄下的指定檔案。 成功刪除檔案時,它會立即從記憶體帳戶的索引中移除,且客戶端無法再存取。 檔案的數據稍後會在垃圾收集期間從服務中移除。

如果檔案在SMB用戶端上開啟,刪除檔案將會失敗,狀態代碼為409(衝突)和錯誤碼SharingViolation。

共用快照集不支援刪除檔案,這是共用的唯讀複本。 嘗試在共用快照集上執行這項作業將會失敗,並產生 400 (InvalidQueryParameterValue)

請參閱 https://learn.microsoft.com/rest/api/storageservices/delete-file2

function deleteFile(fileName: string, options?: FileDeleteOptions): Promise<FileDeleteResponse>

參數

fileName

string

要刪除的檔名

options
FileDeleteOptions

檔案刪除作業的選項。

傳回

檔案刪除回應數據。

deleteIfExists(DirectoryDeleteOptions)

如果存在,則移除指定的空白目錄。 請注意,目錄必須空白,才能刪除目錄。

請參閱 https://learn.microsoft.com/rest/api/storageservices/delete-directory

function deleteIfExists(options?: DirectoryDeleteOptions): Promise<DirectoryDeleteIfExistsResponse>

參數

傳回

deleteSubdirectory(string, DirectoryDeleteOptions)

拿掉這個目錄下指定的空白子目錄。 請注意,目錄必須空白,才能刪除目錄。

請參閱 https://learn.microsoft.com/rest/api/storageservices/delete-directory

function deleteSubdirectory(directoryName: string, options?: DirectoryDeleteOptions): Promise<DirectoryDeleteResponse>

參數

directoryName

string

options
DirectoryDeleteOptions

目錄刪除作業的選項。

傳回

目錄刪除回應數據。

exists(DirectoryExistsOptions)

如果指定的目錄存在,則傳回 true;否則為 false。

注意:請小心使用此函式,因為現有的目錄可能會由其他用戶端或應用程式刪除。 反之亦然,此函式完成後,其他用戶端或應用程式可能會新增新的目錄。

function exists(options?: DirectoryExistsOptions): Promise<boolean>

參數

options
DirectoryExistsOptions

[存在] 作業的選項。

傳回

Promise<boolean>

forceCloseAllHandles(DirectoryForceCloseHandlesSegmentOptions)

強制關閉目錄的所有句柄。

請參閱 https://learn.microsoft.com/rest/api/storageservices/force-close-handles

function forceCloseAllHandles(options?: DirectoryForceCloseHandlesSegmentOptions): Promise<CloseHandlesInfo>

參數

傳回

Promise<CloseHandlesInfo>

forceCloseHandle(string, DirectoryForceCloseHandlesOptions)

強制關閉目錄的特定句柄。

請參閱 https://learn.microsoft.com/rest/api/storageservices/force-close-handles

function forceCloseHandle(handleId: string, options?: DirectoryForceCloseHandlesOptions): Promise<DirectoryForceCloseHandlesResponse>

參數

handleId

string

特定句柄標識碼,不能是星號 “*”。 使用 forceCloseHandlesSegment() 關閉所有句柄。

傳回

getDirectoryClient(string)

建立子目錄的 ShareDirectoryClient 物件。

function getDirectoryClient(subDirectoryName: string): ShareDirectoryClient

參數

subDirectoryName

string

子目錄名稱

傳回

指定子目錄名稱的 ShareDirectoryClient 物件。

範例用法:

import { StorageSharedKeyCredential, ShareServiceClient } from "@azure/storage-file-share";

const account = "<account>";
const accountKey = "<accountkey>";

const credential = new StorageSharedKeyCredential(account, accountKey);
const serviceClient = new ShareServiceClient(
  `https://${account}.file.core.windows.net`,
  credential,
);

const shareName = "<share name>";
const directoryName = "<directory name>";
const shareClient = serviceClient.getShareClient(shareName);
const directoryClient = shareClient.getDirectoryClient(directoryName);
await directoryClient.create();

getFileClient(string)

建立 ShareFileClient 物件。

function getFileClient(fileName: string): ShareFileClient

參數

fileName

string

檔名。

傳回

指定檔名的新 ShareFileClient 物件。

範例用法:

import { StorageSharedKeyCredential, ShareServiceClient } from "@azure/storage-file-share";

const account = "<account>";
const accountKey = "<accountkey>";

const credential = new StorageSharedKeyCredential(account, accountKey);
const serviceClient = new ShareServiceClient(
  `https://${account}.file.core.windows.net`,
  credential,
);

const shareName = "<share name>";
const directoryName = "<directory name>";
const directoryClient = serviceClient.getShareClient(shareName).getDirectoryClient(directoryName);

const content = "Hello World!";
const fileName = `newdirectory${+new Date()}`;
const fileClient = directoryClient.getFileClient(fileName);
await fileClient.create(content.length);
console.log(`Create file ${fileName} successfully`);

// Upload file range
await fileClient.uploadRange(content, 0, content.length);
console.log(`Upload file range "${content}" to ${fileName} successfully`);

getProperties(DirectoryGetPropertiesOptions)

傳回指定目錄的所有系統屬性,也可用來檢查目錄是否存在。 傳回的數據不包含目錄中或任何子目錄中的檔案。

請參閱 https://learn.microsoft.com/rest/api/storageservices/get-directory-properties

function getProperties(options?: DirectoryGetPropertiesOptions): Promise<DirectoryGetPropertiesResponse>

參數

options
DirectoryGetPropertiesOptions

目錄取得屬性作業的選項。

傳回

目錄取得屬性作業的響應數據。

listFilesAndDirectories(DirectoryListFilesAndDirectoriesOptions)

傳回異步反覆運算器,以列出指定帳戶下的所有檔案和目錄。

.byPage() 會傳回異步可反覆運算器,以列出頁面中的檔案和目錄。

使用 for await 語法的範例:

import { StorageSharedKeyCredential, ShareServiceClient } from "@azure/storage-file-share";

const account = "<account>";
const accountKey = "<accountkey>";

const credential = new StorageSharedKeyCredential(account, accountKey);
const serviceClient = new ShareServiceClient(
  `https://${account}.file.core.windows.net`,
  credential,
);

const shareName = "<share name>";
const directoryName = "<directory name>";
const directoryClient = serviceClient.getShareClient(shareName).getDirectoryClient(directoryName);

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

使用 iter.next()的範例:

import { StorageSharedKeyCredential, ShareServiceClient } from "@azure/storage-file-share";

const account = "<account>";
const accountKey = "<accountkey>";

const credential = new StorageSharedKeyCredential(account, accountKey);
const serviceClient = new ShareServiceClient(
  `https://${account}.file.core.windows.net`,
  credential,
);

const shareName = "<share name>";
const directoryName = "<directory name>";
const directoryClient = serviceClient.getShareClient(shareName).getDirectoryClient(directoryName);

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

使用 byPage()的範例:

import { StorageSharedKeyCredential, ShareServiceClient } from "@azure/storage-file-share";

const account = "<account>";
const accountKey = "<accountkey>";

const credential = new StorageSharedKeyCredential(account, accountKey);
const serviceClient = new ShareServiceClient(
  `https://${account}.file.core.windows.net`,
  credential,
);

const shareName = "<share name>";
const directoryName = "<directory name>";
const directoryClient = serviceClient.getShareClient(shareName).getDirectoryClient(directoryName);

let i = 1;
for await (const response of directoryClient
  .listFilesAndDirectories()
  .byPage({ maxPageSize: 20 })) {
  console.log(`Page ${i++}:`);
  for (const item of response.segment.directoryItems) {
    console.log(`\tdirectory: ${item.name}`);
  }
  for (const item of response.segment.fileItems) {
    console.log(`\tfile: ${item.name}`);
  }
}

使用分頁搭配標記的範例:

import { StorageSharedKeyCredential, ShareServiceClient } from "@azure/storage-file-share";

const account = "<account>";
const accountKey = "<accountkey>";

const credential = new StorageSharedKeyCredential(account, accountKey);
const serviceClient = new ShareServiceClient(
  `https://${account}.file.core.windows.net`,
  credential,
);

const shareName = "<share name>";
const directoryName = "<directory name>";
const directoryClient = serviceClient.getShareClient(shareName).getDirectoryClient(directoryName);

let iterator = directoryClient.listFilesAndDirectories().byPage({ maxPageSize: 2 });
let response = (await iterator.next()).value;

for await (const item of response.segment.directoryItems) {
  console.log(`\tdirectory: ${item.name}`);
}

for await (const item of response.segment.fileItems) {
  console.log(`\tfile: ${item.name}`);
}

// Gets next marker
let marker = response.continuationToken;

// Passing next marker as continuationToken
iterator = directoryClient
  .listFilesAndDirectories()
  .byPage({ continuationToken: marker, maxPageSize: 10 });
response = (await iterator.next()).value;

for await (const item of response.segment.directoryItems) {
  console.log(`\tdirectory: ${item.name}`);
}

for await (const item of response.segment.fileItems) {
  console.log(`\tfile: ${item.name}`);
}
function listFilesAndDirectories(options?: DirectoryListFilesAndDirectoriesOptions): PagedAsyncIterableIterator<({ kind: "file" } & FileItem) | ({ kind: "directory" } & DirectoryItem), DirectoryListFilesAndDirectoriesSegmentResponse, PageSettings>

參數

options
DirectoryListFilesAndDirectoriesOptions

列出檔案和目錄作業的選項。

傳回

支援分頁的 asyncIterableIterator。

listHandles(DirectoryListHandlesOptions)

傳回異步反覆運算器以列出所有句柄。 在指定的帳戶下。

.byPage() 會傳回異步反覆運算器,以列出頁面中的句柄。

使用 for await 語法的範例:

import { StorageSharedKeyCredential, ShareServiceClient } from "@azure/storage-file-share";

const account = "<account>";
const accountKey = "<accountkey>";

const credential = new StorageSharedKeyCredential(account, accountKey);
const serviceClient = new ShareServiceClient(
  `https://${account}.file.core.windows.net`,
  credential,
);

const shareName = "<share name>";
const directoryName = "<directory name>";
const directoryClient = serviceClient.getShareClient(shareName).getDirectoryClient(directoryName);

for await (const handle of directoryClient.listHandles()) {
  console.log(`Handle: ${handle.handleId}`);
}

使用 iter.next()的範例:

import { StorageSharedKeyCredential, ShareServiceClient } from "@azure/storage-file-share";

const account = "<account>";
const accountKey = "<accountkey>";

const credential = new StorageSharedKeyCredential(account, accountKey);
const serviceClient = new ShareServiceClient(
  `https://${account}.file.core.windows.net`,
  credential,
);

const shareName = "<share name>";
const directoryName = "<directory name>";
const directoryClient = serviceClient.getShareClient(shareName).getDirectoryClient(directoryName);

const handleIter = directoryClient.listHandles();
let { value, done } = await handleIter.next();
while (!done) {
  console.log(`Handle: ${value.handleId}`);
  ({ value, done } = await handleIter.next());
}

使用 byPage()的範例:

import { StorageSharedKeyCredential, ShareServiceClient } from "@azure/storage-file-share";

const account = "<account>";
const accountKey = "<accountkey>";

const credential = new StorageSharedKeyCredential(account, accountKey);
const serviceClient = new ShareServiceClient(
  `https://${account}.file.core.windows.net`,
  credential,
);

const shareName = "<share name>";
const directoryName = "<directory name>";
const directoryClient = serviceClient.getShareClient(shareName).getDirectoryClient(directoryName);

let i = 1;
for await (const response of directoryClient.listHandles().byPage({ maxPageSize: 20 })) {
  console.log(`Page ${i++}:`);
  for (const handle of response.handleList || []) {
    console.log(`\thandle: ${handle.handleId}`);
  }
}

使用分頁搭配標記的範例:

import { StorageSharedKeyCredential, ShareServiceClient } from "@azure/storage-file-share";

const account = "<account>";
const accountKey = "<accountkey>";

const credential = new StorageSharedKeyCredential(account, accountKey);
const serviceClient = new ShareServiceClient(
  `https://${account}.file.core.windows.net`,
  credential,
);

const shareName = "<share name>";
const directoryName = "<directory name>";
const directoryClient = serviceClient.getShareClient(shareName).getDirectoryClient(directoryName);

let iterator = directoryClient.listHandles().byPage({ maxPageSize: 2 });
let response = (await iterator.next()).value;

for await (const handle of response.handleList || []) {
  console.log(`\thandle: ${handle.handleId}`);
}

// Gets next marker
let marker = response.continuationToken;

// Passing next marker as continuationToken
iterator = directoryClient.listHandles().byPage({ continuationToken: marker, maxPageSize: 10 });
response = (await iterator.next()).value;

for await (const handle of response.handleList || []) {
  console.log(`\thandle: ${handle.handleId}`);
}
function listHandles(options?: DirectoryListHandlesOptions): PagedAsyncIterableIterator<HandleItem, DirectoryListHandlesResponse, PageSettings>

參數

options
DirectoryListHandlesOptions

列出處理作業的選項。

支援分頁的 asyncIterableIterator。

傳回

rename(string, DirectoryRenameOptions)

重新命名目錄。 此 API 僅支援在相同共用中重新命名目錄。

function rename(destinationPath: string, options?: DirectoryRenameOptions): Promise<{ destinationDirectoryClient: ShareDirectoryClient, directoryRenameResponse: DirectoryRenameResponse }>

參數

destinationPath

string

指定要重新命名的目標路徑。 路徑會經過編碼,以放入URL以指定目的地。

options
DirectoryRenameOptions

重新命名作業的選項。

傳回

Promise<{ destinationDirectoryClient: ShareDirectoryClient, directoryRenameResponse: DirectoryRenameResponse }>

檔案重新命名作業的響應數據。

範例用法:

import { StorageSharedKeyCredential, ShareServiceClient } from "@azure/storage-file-share";

const account = "<account>";
const accountKey = "<accountkey>";

const credential = new StorageSharedKeyCredential(account, accountKey);
const serviceClient = new ShareServiceClient(
  `https://${account}.file.core.windows.net`,
  credential,
);

const shareName = "<share name>";
const directoryName = "<directory name>";
const destinationPath = "<destination path>";
const directoryClient = serviceClient.getShareClient(shareName).getDirectoryClient(directoryName);

await directoryClient.rename(destinationPath);

setMetadata(Metadata, DirectorySetMetadataOptions)

更新指定目錄的使用者定義元數據。

請參閱 https://learn.microsoft.com/rest/api/storageservices/set-directory-metadata

function setMetadata(metadata?: Metadata, options?: DirectorySetMetadataOptions): Promise<DirectorySetMetadataResponse>

參數

metadata
Metadata

如果未提供任何元數據,則會移除所有現有的目錄元數據

options
DirectorySetMetadataOptions

目錄設定元數據作業的選項。

傳回

目錄集合元數據作業的響應數據。

setProperties(DirectoryProperties)

設定目錄上的屬性。

請參閱 https://learn.microsoft.com/rest/api/storageservices/set-directory-properties

function setProperties(properties?: DirectoryProperties): Promise<DirectorySetPropertiesResponse>

參數

properties
DirectoryProperties

傳回