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 Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loTextCompare
LOCAL loConfig
LOCAL lnSameText1
LOCAL lnSameText2
LOCAL loEndpoint
LOCAL lcResourcePath
LOCAL loRest
LOCAL loAzAuth
LOCAL loConnection
LOCAL lcResponseText
LOCAL loResult
LOCAL loSeenMarkers
LOCAL lcMarker
LOCAL lnMore
LOCAL lnPage
LOCAL lnDirectoryCount
LOCAL lnDirectoryIndex
LOCAL lcDirectoryName
LOCAL lnSameText3
LOCAL lnSameText4
LOCAL loDecodedDirectory
LOCAL lnFileCount
LOCAL lnFileIndex
LOCAL lcFileName
LOCAL lnSameText5
LOCAL lnSameText6
LOCAL loDecodedFile
LOCAL lnSameText7
lnSuccess = 0
* StringBuilder compares text by value in every generated language.
loTextCompare = CreateObject('Chilkat.StringBuilder')
* Assumes Chilkat is unlocked. See Global Unlock Sample.
lnSuccess = 0
loConfig = CreateObject('Chilkat.JsonObject')
loConfig.Strict = 1
lnSuccess = loConfig.LoadFile("qa_data/azure/storage.json")
IF (lnSuccess <> 1) THEN
? "Could not load private Azure configuration."
RELEASE loTextCompare
RELEASE loConfig
CANCEL
ENDIF
loTextCompare.Clear()
loTextCompare.SetString(loConfig.StringOf("account"))
lnSameText1 = loTextCompare.ContentsEqual("",1)
IF ((loConfig.JsonTypeOf("account") <> 1) OR (lnSameText1 = 1)) THEN
? "Supply the storage account name."
RELEASE loTextCompare
RELEASE loConfig
CANCEL
ENDIF
* access_key is the base64 account key, not a connection string or SAS.
loTextCompare.Clear()
loTextCompare.SetString(loConfig.StringOf("access_key"))
lnSameText2 = loTextCompare.ContentsEqual("",1)
IF ((loConfig.JsonTypeOf("access_key") <> 1) OR (lnSameText2 = 1)) THEN
? "Supply the base64 account access key."
RELEASE loTextCompare
RELEASE loConfig
CANCEL
ENDIF
loEndpoint = CreateObject('Chilkat.StringBuilder')
lnSuccess = loEndpoint.Append(loConfig.StringOf("account"))
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loEndpoint
CANCEL
ENDIF
lnSuccess = loEndpoint.Append(".file.core.windows.net")
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loEndpoint
CANCEL
ENDIF
* resourcePath is already URL-encoded. Encode each path segment once when adapting it.
* Keep slash separators; names and paths are case-sensitive.
lcResourcePath = "/examples/files"
loRest = CreateObject('Chilkat.Rest')
loRest.ConnectTimeoutMs = 20000
loRest.IdleTimeoutMs = 60000
loAzAuth = CreateObject('Chilkat.AuthAzureStorage')
loAzAuth.Account = loConfig.StringOf("account")
loAzAuth.AccessKey = loConfig.StringOf("access_key")
loAzAuth.Service = "File"
loAzAuth.Scheme = "SharedKey"
loAzAuth.XMsVersion = "2026-04-06"
lnSuccess = loRest.SetAuthAzureStorage(loAzAuth)
IF (lnSuccess <> 1) THEN
? "Could not configure Shared Key signing."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loEndpoint
RELEASE loRest
RELEASE loAzAuth
CANCEL
ENDIF
loConnection = CreateObject('Chilkat.Socket')
loConnection.RequireSslCertVerify = 1
loConnection.MaxReadIdleMs = 60000
loConnection.MaxSendIdleMs = 60000
lnSuccess = loConnection.Connect(loEndpoint.GetAsString(),443,1,20000)
IF (lnSuccess <> 1) THEN
? "TLS connection failed; inspect diagnostics privately."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loEndpoint
RELEASE loRest
RELEASE loAzAuth
RELEASE loConnection
CANCEL
ENDIF
* Do not replay a write automatically after losing its response.
lnSuccess = loRest.UseConnection(loConnection,0)
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loEndpoint
RELEASE loRest
RELEASE loAzAuth
RELEASE loConnection
CANCEL
ENDIF
loResult = CreateObject('Chilkat.Xml')
loResult.Strict = 1
lnSuccess = loRest.AddQueryParam("restype","directory")
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loEndpoint
RELEASE loRest
RELEASE loAzAuth
RELEASE loConnection
RELEASE loResult
CANCEL
ENDIF
lnSuccess = loRest.AddQueryParam("comp","list")
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loEndpoint
RELEASE loRest
RELEASE loAzAuth
RELEASE loConnection
RELEASE loResult
CANCEL
ENDIF
lnSuccess = loRest.AddHeader("x-ms-file-extended-info","true")
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loEndpoint
RELEASE loRest
RELEASE loAzAuth
RELEASE loConnection
RELEASE loResult
CANCEL
ENDIF
lnSuccess = loRest.AddQueryParam("maxresults","1000")
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loEndpoint
RELEASE loRest
RELEASE loAzAuth
RELEASE loConnection
RELEASE loResult
CANCEL
ENDIF
loSeenMarkers = CreateObject('Chilkat.Hashtable')
lcMarker = ""
lnMore = 1
lnPage = 0
DO WHILE (lnMore = 1)
IF (lnPage >= 1000) THEN
? "Page limit reached; results are incomplete. Save the continuation marker."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loEndpoint
RELEASE loRest
RELEASE loAzAuth
RELEASE loConnection
RELEASE loResult
RELEASE loSeenMarkers
CANCEL
ENDIF
lcResponseText = loRest.FullRequestNoBody("GET",lcResourcePath)
IF (loRest.LastMethodSuccess <> 1) THEN
? "Request did not complete; outcome may be uncertain."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loEndpoint
RELEASE loRest
RELEASE loAzAuth
RELEASE loConnection
RELEASE loResult
RELEASE loSeenMarkers
CANCEL
ENDIF
IF (loRest.ResponseStatusCode <> 200) THEN
? "HTTP status: " + STR(loRest.ResponseStatusCode)
? "Azure error code: " + loRest.ResponseHdrByName("x-ms-error-code")
? "Request ID: " + loRest.ResponseHdrByName("x-ms-request-id")
* Inspect any error body privately; do not log credentials, SAS URLs or payloads.
RELEASE loTextCompare
RELEASE loConfig
RELEASE loEndpoint
RELEASE loRest
RELEASE loAzAuth
RELEASE loConnection
RELEASE loResult
RELEASE loSeenMarkers
CANCEL
ENDIF
lnSuccess = loResult.LoadXml(lcResponseText)
IF (lnSuccess <> 1) THEN
? "Expected well-formed XML."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loEndpoint
RELEASE loRest
RELEASE loAzAuth
RELEASE loConnection
RELEASE loResult
RELEASE loSeenMarkers
CANCEL
ENDIF
IF (loResult.TagEquals("EnumerationResults") <> 1) THEN
? "Unexpected XML response root."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loEndpoint
RELEASE loRest
RELEASE loAzAuth
RELEASE loConnection
RELEASE loResult
RELEASE loSeenMarkers
CANCEL
ENDIF
lnSuccess = loResult.FindChild2("Entries")
IF (lnSuccess <> 1) THEN
? "Missing directory Entries element."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loEndpoint
RELEASE loRest
RELEASE loAzAuth
RELEASE loConnection
RELEASE loResult
RELEASE loSeenMarkers
CANCEL
ENDIF
lnDirectoryCount = loResult.NumChildrenHavingTag("Directory")
lnDirectoryIndex = 0
DO WHILE (lnDirectoryIndex < lnDirectoryCount)
loResult.I = lnDirectoryIndex
lcDirectoryName = loResult.GetChildContent("Directory[i]|Name")
loTextCompare.Clear()
loTextCompare.SetString(lcDirectoryName)
lnSameText3 = loTextCompare.ContentsEqual("",1)
IF (lnSameText3 <> 1) THEN
loTextCompare.Clear()
loTextCompare.SetString(loResult.GetChildAttrValue("Directory[i]|Name","Encoded"))
lnSameText4 = loTextCompare.ContentsEqual("true",1)
IF (lnSameText4 = 1) THEN
loDecodedDirectory = CreateObject('Chilkat.StringBuilder')
lnSuccess = loDecodedDirectory.Append(lcDirectoryName)
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loEndpoint
RELEASE loRest
RELEASE loAzAuth
RELEASE loConnection
RELEASE loResult
RELEASE loSeenMarkers
RELEASE loDecodedDirectory
CANCEL
ENDIF
lnSuccess = loDecodedDirectory.Decode("url","utf-8")
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loEndpoint
RELEASE loRest
RELEASE loAzAuth
RELEASE loConnection
RELEASE loResult
RELEASE loSeenMarkers
RELEASE loDecodedDirectory
CANCEL
ENDIF
lcDirectoryName = loDecodedDirectory.GetAsString()
ENDIF
? "Directory: " + lcDirectoryName
? "File ID: " + loResult.GetChildContent("Directory[i]|FileId")
ENDIF
lnDirectoryIndex = lnDirectoryIndex + 1
ENDDO
lnFileCount = loResult.NumChildrenHavingTag("File")
lnFileIndex = 0
DO WHILE (lnFileIndex < lnFileCount)
loResult.I = lnFileIndex
lcFileName = loResult.GetChildContent("File[i]|Name")
loTextCompare.Clear()
loTextCompare.SetString(lcFileName)
lnSameText5 = loTextCompare.ContentsEqual("",1)
IF (lnSameText5 <> 1) THEN
loTextCompare.Clear()
loTextCompare.SetString(loResult.GetChildAttrValue("File[i]|Name","Encoded"))
lnSameText6 = loTextCompare.ContentsEqual("true",1)
IF (lnSameText6 = 1) THEN
loDecodedFile = CreateObject('Chilkat.StringBuilder')
lnSuccess = loDecodedFile.Append(lcFileName)
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loEndpoint
RELEASE loRest
RELEASE loAzAuth
RELEASE loConnection
RELEASE loResult
RELEASE loSeenMarkers
RELEASE loDecodedDirectory
RELEASE loDecodedFile
CANCEL
ENDIF
lnSuccess = loDecodedFile.Decode("url","utf-8")
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loEndpoint
RELEASE loRest
RELEASE loAzAuth
RELEASE loConnection
RELEASE loResult
RELEASE loSeenMarkers
RELEASE loDecodedDirectory
RELEASE loDecodedFile
CANCEL
ENDIF
lcFileName = loDecodedFile.GetAsString()
ENDIF
? "File: " + lcFileName
? "File ID: " + loResult.GetChildContent("File[i]|FileId")
? "Size: " + loResult.GetChildContent("File[i]|Properties|Content-Length")
ENDIF
lnFileIndex = lnFileIndex + 1
ENDDO
lnSuccess = loResult.GetParent2()
IF (lnSuccess <> 1) THEN
? "Could not return to enumeration root."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loEndpoint
RELEASE loRest
RELEASE loAzAuth
RELEASE loConnection
RELEASE loResult
RELEASE loSeenMarkers
RELEASE loDecodedDirectory
RELEASE loDecodedFile
CANCEL
ENDIF
lcMarker = loResult.GetChildContent("NextMarker")
lnPage = lnPage + 1
loTextCompare.Clear()
loTextCompare.SetString(lcMarker)
lnSameText7 = loTextCompare.ContentsEqual("",1)
IF (lnSameText7 = 1) THEN
lnMore = 0
ELSE
IF (loSeenMarkers.Contains(lcMarker) = 1) THEN
? "Repeated marker; results are incomplete."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loEndpoint
RELEASE loRest
RELEASE loAzAuth
RELEASE loConnection
RELEASE loResult
RELEASE loSeenMarkers
RELEASE loDecodedDirectory
RELEASE loDecodedFile
CANCEL
ENDIF
lnSuccess = loSeenMarkers.AddInt(lcMarker,1)
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loEndpoint
RELEASE loRest
RELEASE loAzAuth
RELEASE loConnection
RELEASE loResult
RELEASE loSeenMarkers
RELEASE loDecodedDirectory
RELEASE loDecodedFile
CANCEL
ENDIF
IF (lnPage > 1) THEN
lnSuccess = loRest.RemoveQueryParam("marker")
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loEndpoint
RELEASE loRest
RELEASE loAzAuth
RELEASE loConnection
RELEASE loResult
RELEASE loSeenMarkers
RELEASE loDecodedDirectory
RELEASE loDecodedFile
CANCEL
ENDIF
ENDIF
lnSuccess = loRest.AddQueryParam("marker",lcMarker)
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loEndpoint
RELEASE loRest
RELEASE loAzAuth
RELEASE loConnection
RELEASE loResult
RELEASE loSeenMarkers
RELEASE loDecodedDirectory
RELEASE loDecodedFile
CANCEL
ENDIF
loRest.Disconnect(10)
lnSuccess = loConnection.Connect(loEndpoint.GetAsString(),443,1,20000)
IF (lnSuccess <> 1) THEN
? "TLS reconnection failed."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loEndpoint
RELEASE loRest
RELEASE loAzAuth
RELEASE loConnection
RELEASE loResult
RELEASE loSeenMarkers
RELEASE loDecodedDirectory
RELEASE loDecodedFile
CANCEL
ENDIF
lnSuccess = loRest.UseConnection(loConnection,0)
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loEndpoint
RELEASE loRest
RELEASE loAzAuth
RELEASE loConnection
RELEASE loResult
RELEASE loSeenMarkers
RELEASE loDecodedDirectory
RELEASE loDecodedFile
CANCEL
ENDIF
ENDIF
ENDDO
? "Directory listing complete."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loEndpoint
RELEASE loRest
RELEASE loAzAuth
RELEASE loConnection
RELEASE loResult
RELEASE loSeenMarkers
RELEASE loDecodedDirectory
RELEASE loDecodedFile