Azure Files: List Directories and Files with Pagination
See more Azure Cloud Storage Examples
List the immediate children of an existing directory in an SMB file share. Follow continuation markers even after an empty page, distinguish files from directories, and keep FileId and Content-Length as strings. This is not recursive; an application can queue discovered directories for traversal.
x-ms-file-extended-info requests current SMB file sizes. Enumeration is not an immutable snapshot when other clients are changing files. Name elements marked Encoded=true are URL-decoded for display; encode individual path segments again when constructing a subsequent request.
Uses direct Chilkat.Rest requests and Azure public-cloud endpoints with verified HTTPS. REST requests select service version 2026-04-06. Create local input/output directories before running. Account-key examples read account and access_key string fields from private qa_data/azure/storage.json; do not embed secrets in distributed applications. Entra examples explain their own configuration. Keep credentials, bearer tokens, SAS URLs and diagnostic dumps private. Shared Key is supported only where allowed by account policy; Entra authentication is preferred where available.
Transport success and HTTP status are checked separately. Writes are not automatically replayed after an uncertain response. IDs, ETags, continuation markers and file sizes are strings; counters and explicitly bounded offsets use int. No webhook or web server is required.
Chilkat PowerBuilder Downloads
integer li_rc
long li_Success
oleobject loo_TextCompare
oleobject loo_Config
long li_SameText1
long li_SameText2
oleobject loo_Endpoint
string ls_ResourcePath
oleobject loo_Rest
oleobject loo_AzAuth
oleobject loo_Connection
string ls_ResponseText
oleobject loo_Result
oleobject loo_SeenMarkers
string ls_Marker
long li_More
long li_Page
long li_DirectoryCount
long li_DirectoryIndex
string ls_DirectoryName
long li_SameText3
long li_SameText4
oleobject loo_DecodedDirectory
long li_FileCount
long li_FileIndex
string ls_FileName
long li_SameText5
long li_SameText6
oleobject loo_DecodedFile
long li_SameText7
li_Success = 0
// StringBuilder compares text by value in every generated language.
loo_TextCompare = create oleobject
li_rc = loo_TextCompare.ConnectToNewObject("Chilkat.StringBuilder")
if li_rc < 0 then
destroy loo_TextCompare
MessageBox("Error","Connecting to COM object failed")
return
end if
// Assumes Chilkat is unlocked. See Global Unlock Sample.
li_Success = 0
loo_Config = create oleobject
li_rc = loo_Config.ConnectToNewObject("Chilkat.JsonObject")
loo_Config.Strict = 1
li_Success = loo_Config.LoadFile("qa_data/azure/storage.json")
if li_Success <> 1 then
Write-Debug "Could not load private Azure configuration."
destroy loo_TextCompare
destroy loo_Config
return
end if
loo_TextCompare.Clear()
loo_TextCompare.SetString(loo_Config.StringOf("account"))
li_SameText1 = loo_TextCompare.ContentsEqual("",1)
if (loo_Config.JsonTypeOf("account") <> 1) OR (li_SameText1 = 1) then
Write-Debug "Supply the storage account name."
destroy loo_TextCompare
destroy loo_Config
return
end if
// access_key is the base64 account key, not a connection string or SAS.
loo_TextCompare.Clear()
loo_TextCompare.SetString(loo_Config.StringOf("access_key"))
li_SameText2 = loo_TextCompare.ContentsEqual("",1)
if (loo_Config.JsonTypeOf("access_key") <> 1) OR (li_SameText2 = 1) then
Write-Debug "Supply the base64 account access key."
destroy loo_TextCompare
destroy loo_Config
return
end if
loo_Endpoint = create oleobject
li_rc = loo_Endpoint.ConnectToNewObject("Chilkat.StringBuilder")
li_Success = loo_Endpoint.Append(loo_Config.StringOf("account"))
if li_Success <> 1 then
Write-Debug "Could not prepare the request."
destroy loo_TextCompare
destroy loo_Config
destroy loo_Endpoint
return
end if
li_Success = loo_Endpoint.Append(".file.core.windows.net")
if li_Success <> 1 then
Write-Debug "Could not prepare the request."
destroy loo_TextCompare
destroy loo_Config
destroy loo_Endpoint
return
end if
// resourcePath is already URL-encoded. Encode each path segment once when adapting it.
// Keep slash separators; names and paths are case-sensitive.
ls_ResourcePath = "/examples/files"
loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat.Rest")
loo_Rest.ConnectTimeoutMs = 20000
loo_Rest.IdleTimeoutMs = 60000
loo_AzAuth = create oleobject
li_rc = loo_AzAuth.ConnectToNewObject("Chilkat.AuthAzureStorage")
loo_AzAuth.Account = loo_Config.StringOf("account")
loo_AzAuth.AccessKey = loo_Config.StringOf("access_key")
loo_AzAuth.Service = "File"
loo_AzAuth.Scheme = "SharedKey"
loo_AzAuth.XMsVersion = "2026-04-06"
li_Success = loo_Rest.SetAuthAzureStorage(loo_AzAuth)
if li_Success <> 1 then
Write-Debug "Could not configure Shared Key signing."
destroy loo_TextCompare
destroy loo_Config
destroy loo_Endpoint
destroy loo_Rest
destroy loo_AzAuth
return
end if
loo_Connection = create oleobject
li_rc = loo_Connection.ConnectToNewObject("Chilkat.Socket")
loo_Connection.RequireSslCertVerify = 1
loo_Connection.MaxReadIdleMs = 60000
loo_Connection.MaxSendIdleMs = 60000
li_Success = loo_Connection.Connect(loo_Endpoint.GetAsString(),443,1,20000)
if li_Success <> 1 then
Write-Debug "TLS connection failed; inspect diagnostics privately."
destroy loo_TextCompare
destroy loo_Config
destroy loo_Endpoint
destroy loo_Rest
destroy loo_AzAuth
destroy loo_Connection
return
end if
// Do not replay a write automatically after losing its response.
li_Success = loo_Rest.UseConnection(loo_Connection,0)
if li_Success <> 1 then
Write-Debug "Could not prepare the request."
destroy loo_TextCompare
destroy loo_Config
destroy loo_Endpoint
destroy loo_Rest
destroy loo_AzAuth
destroy loo_Connection
return
end if
loo_Result = create oleobject
li_rc = loo_Result.ConnectToNewObject("Chilkat.Xml")
loo_Result.Strict = 1
li_Success = loo_Rest.AddQueryParam("restype","directory")
if li_Success <> 1 then
Write-Debug "Could not prepare the request."
destroy loo_TextCompare
destroy loo_Config
destroy loo_Endpoint
destroy loo_Rest
destroy loo_AzAuth
destroy loo_Connection
destroy loo_Result
return
end if
li_Success = loo_Rest.AddQueryParam("comp","list")
if li_Success <> 1 then
Write-Debug "Could not prepare the request."
destroy loo_TextCompare
destroy loo_Config
destroy loo_Endpoint
destroy loo_Rest
destroy loo_AzAuth
destroy loo_Connection
destroy loo_Result
return
end if
li_Success = loo_Rest.AddHeader("x-ms-file-extended-info","true")
if li_Success <> 1 then
Write-Debug "Could not prepare the request."
destroy loo_TextCompare
destroy loo_Config
destroy loo_Endpoint
destroy loo_Rest
destroy loo_AzAuth
destroy loo_Connection
destroy loo_Result
return
end if
li_Success = loo_Rest.AddQueryParam("maxresults","1000")
if li_Success <> 1 then
Write-Debug "Could not prepare the request."
destroy loo_TextCompare
destroy loo_Config
destroy loo_Endpoint
destroy loo_Rest
destroy loo_AzAuth
destroy loo_Connection
destroy loo_Result
return
end if
loo_SeenMarkers = create oleobject
li_rc = loo_SeenMarkers.ConnectToNewObject("Chilkat.Hashtable")
ls_Marker = ""
li_More = 1
li_Page = 0
do while (li_More = 1)
if li_Page >= 1000 then
Write-Debug "Page limit reached; results are incomplete. Save the continuation marker."
destroy loo_TextCompare
destroy loo_Config
destroy loo_Endpoint
destroy loo_Rest
destroy loo_AzAuth
destroy loo_Connection
destroy loo_Result
destroy loo_SeenMarkers
return
end if
ls_ResponseText = loo_Rest.FullRequestNoBody("GET",ls_ResourcePath)
if loo_Rest.LastMethodSuccess <> 1 then
Write-Debug "Request did not complete; outcome may be uncertain."
destroy loo_TextCompare
destroy loo_Config
destroy loo_Endpoint
destroy loo_Rest
destroy loo_AzAuth
destroy loo_Connection
destroy loo_Result
destroy loo_SeenMarkers
return
end if
if loo_Rest.ResponseStatusCode <> 200 then
Write-Debug "HTTP status: " + string(loo_Rest.ResponseStatusCode)
Write-Debug "Azure error code: " + loo_Rest.ResponseHdrByName("x-ms-error-code")
Write-Debug "Request ID: " + loo_Rest.ResponseHdrByName("x-ms-request-id")
// Inspect any error body privately; do not log credentials, SAS URLs or payloads.
destroy loo_TextCompare
destroy loo_Config
destroy loo_Endpoint
destroy loo_Rest
destroy loo_AzAuth
destroy loo_Connection
destroy loo_Result
destroy loo_SeenMarkers
return
end if
li_Success = loo_Result.LoadXml(ls_ResponseText)
if li_Success <> 1 then
Write-Debug "Expected well-formed XML."
destroy loo_TextCompare
destroy loo_Config
destroy loo_Endpoint
destroy loo_Rest
destroy loo_AzAuth
destroy loo_Connection
destroy loo_Result
destroy loo_SeenMarkers
return
end if
if loo_Result.TagEquals("EnumerationResults") <> 1 then
Write-Debug "Unexpected XML response root."
destroy loo_TextCompare
destroy loo_Config
destroy loo_Endpoint
destroy loo_Rest
destroy loo_AzAuth
destroy loo_Connection
destroy loo_Result
destroy loo_SeenMarkers
return
end if
li_Success = loo_Result.FindChild2("Entries")
if li_Success <> 1 then
Write-Debug "Missing directory Entries element."
destroy loo_TextCompare
destroy loo_Config
destroy loo_Endpoint
destroy loo_Rest
destroy loo_AzAuth
destroy loo_Connection
destroy loo_Result
destroy loo_SeenMarkers
return
end if
li_DirectoryCount = loo_Result.NumChildrenHavingTag("Directory")
li_DirectoryIndex = 0
do while (li_DirectoryIndex < li_DirectoryCount)
loo_Result.I = li_DirectoryIndex
ls_DirectoryName = loo_Result.GetChildContent("Directory[i]|Name")
loo_TextCompare.Clear()
loo_TextCompare.SetString(ls_DirectoryName)
li_SameText3 = loo_TextCompare.ContentsEqual("",1)
if li_SameText3 <> 1 then
loo_TextCompare.Clear()
loo_TextCompare.SetString(loo_Result.GetChildAttrValue("Directory[i]|Name","Encoded"))
li_SameText4 = loo_TextCompare.ContentsEqual("true",1)
if li_SameText4 = 1 then
loo_DecodedDirectory = create oleobject
li_rc = loo_DecodedDirectory.ConnectToNewObject("Chilkat.StringBuilder")
li_Success = loo_DecodedDirectory.Append(ls_DirectoryName)
if li_Success <> 1 then
Write-Debug "Could not prepare the request."
destroy loo_TextCompare
destroy loo_Config
destroy loo_Endpoint
destroy loo_Rest
destroy loo_AzAuth
destroy loo_Connection
destroy loo_Result
destroy loo_SeenMarkers
destroy loo_DecodedDirectory
return
end if
li_Success = loo_DecodedDirectory.Decode("url","utf-8")
if li_Success <> 1 then
Write-Debug "Could not prepare the request."
destroy loo_TextCompare
destroy loo_Config
destroy loo_Endpoint
destroy loo_Rest
destroy loo_AzAuth
destroy loo_Connection
destroy loo_Result
destroy loo_SeenMarkers
destroy loo_DecodedDirectory
return
end if
ls_DirectoryName = loo_DecodedDirectory.GetAsString()
end if
Write-Debug "Directory: " + ls_DirectoryName
Write-Debug "File ID: " + loo_Result.GetChildContent("Directory[i]|FileId")
end if
li_DirectoryIndex = li_DirectoryIndex + 1
loop
li_FileCount = loo_Result.NumChildrenHavingTag("File")
li_FileIndex = 0
do while (li_FileIndex < li_FileCount)
loo_Result.I = li_FileIndex
ls_FileName = loo_Result.GetChildContent("File[i]|Name")
loo_TextCompare.Clear()
loo_TextCompare.SetString(ls_FileName)
li_SameText5 = loo_TextCompare.ContentsEqual("",1)
if li_SameText5 <> 1 then
loo_TextCompare.Clear()
loo_TextCompare.SetString(loo_Result.GetChildAttrValue("File[i]|Name","Encoded"))
li_SameText6 = loo_TextCompare.ContentsEqual("true",1)
if li_SameText6 = 1 then
loo_DecodedFile = create oleobject
li_rc = loo_DecodedFile.ConnectToNewObject("Chilkat.StringBuilder")
li_Success = loo_DecodedFile.Append(ls_FileName)
if li_Success <> 1 then
Write-Debug "Could not prepare the request."
destroy loo_TextCompare
destroy loo_Config
destroy loo_Endpoint
destroy loo_Rest
destroy loo_AzAuth
destroy loo_Connection
destroy loo_Result
destroy loo_SeenMarkers
destroy loo_DecodedDirectory
destroy loo_DecodedFile
return
end if
li_Success = loo_DecodedFile.Decode("url","utf-8")
if li_Success <> 1 then
Write-Debug "Could not prepare the request."
destroy loo_TextCompare
destroy loo_Config
destroy loo_Endpoint
destroy loo_Rest
destroy loo_AzAuth
destroy loo_Connection
destroy loo_Result
destroy loo_SeenMarkers
destroy loo_DecodedDirectory
destroy loo_DecodedFile
return
end if
ls_FileName = loo_DecodedFile.GetAsString()
end if
Write-Debug "File: " + ls_FileName
Write-Debug "File ID: " + loo_Result.GetChildContent("File[i]|FileId")
Write-Debug "Size: " + loo_Result.GetChildContent("File[i]|Properties|Content-Length")
end if
li_FileIndex = li_FileIndex + 1
loop
li_Success = loo_Result.GetParent2()
if li_Success <> 1 then
Write-Debug "Could not return to enumeration root."
destroy loo_TextCompare
destroy loo_Config
destroy loo_Endpoint
destroy loo_Rest
destroy loo_AzAuth
destroy loo_Connection
destroy loo_Result
destroy loo_SeenMarkers
destroy loo_DecodedDirectory
destroy loo_DecodedFile
return
end if
ls_Marker = loo_Result.GetChildContent("NextMarker")
li_Page = li_Page + 1
loo_TextCompare.Clear()
loo_TextCompare.SetString(ls_Marker)
li_SameText7 = loo_TextCompare.ContentsEqual("",1)
if li_SameText7 = 1 then
li_More = 0
else
if loo_SeenMarkers.Contains(ls_Marker) = 1 then
Write-Debug "Repeated marker; results are incomplete."
destroy loo_TextCompare
destroy loo_Config
destroy loo_Endpoint
destroy loo_Rest
destroy loo_AzAuth
destroy loo_Connection
destroy loo_Result
destroy loo_SeenMarkers
destroy loo_DecodedDirectory
destroy loo_DecodedFile
return
end if
li_Success = loo_SeenMarkers.AddInt(ls_Marker,1)
if li_Success <> 1 then
Write-Debug "Could not prepare the request."
destroy loo_TextCompare
destroy loo_Config
destroy loo_Endpoint
destroy loo_Rest
destroy loo_AzAuth
destroy loo_Connection
destroy loo_Result
destroy loo_SeenMarkers
destroy loo_DecodedDirectory
destroy loo_DecodedFile
return
end if
if li_Page > 1 then
li_Success = loo_Rest.RemoveQueryParam("marker")
if li_Success <> 1 then
Write-Debug "Could not prepare the request."
destroy loo_TextCompare
destroy loo_Config
destroy loo_Endpoint
destroy loo_Rest
destroy loo_AzAuth
destroy loo_Connection
destroy loo_Result
destroy loo_SeenMarkers
destroy loo_DecodedDirectory
destroy loo_DecodedFile
return
end if
end if
li_Success = loo_Rest.AddQueryParam("marker",ls_Marker)
if li_Success <> 1 then
Write-Debug "Could not prepare the request."
destroy loo_TextCompare
destroy loo_Config
destroy loo_Endpoint
destroy loo_Rest
destroy loo_AzAuth
destroy loo_Connection
destroy loo_Result
destroy loo_SeenMarkers
destroy loo_DecodedDirectory
destroy loo_DecodedFile
return
end if
loo_Rest.Disconnect(10)
li_Success = loo_Connection.Connect(loo_Endpoint.GetAsString(),443,1,20000)
if li_Success <> 1 then
Write-Debug "TLS reconnection failed."
destroy loo_TextCompare
destroy loo_Config
destroy loo_Endpoint
destroy loo_Rest
destroy loo_AzAuth
destroy loo_Connection
destroy loo_Result
destroy loo_SeenMarkers
destroy loo_DecodedDirectory
destroy loo_DecodedFile
return
end if
li_Success = loo_Rest.UseConnection(loo_Connection,0)
if li_Success <> 1 then
Write-Debug "Could not prepare the request."
destroy loo_TextCompare
destroy loo_Config
destroy loo_Endpoint
destroy loo_Rest
destroy loo_AzAuth
destroy loo_Connection
destroy loo_Result
destroy loo_SeenMarkers
destroy loo_DecodedDirectory
destroy loo_DecodedFile
return
end if
end if
loop
Write-Debug "Directory listing complete."
destroy loo_TextCompare
destroy loo_Config
destroy loo_Endpoint
destroy loo_Rest
destroy loo_AzAuth
destroy loo_Connection
destroy loo_Result
destroy loo_SeenMarkers
destroy loo_DecodedDirectory
destroy loo_DecodedFile