Sample code for 30+ languages & platforms
DataFlex Requires Chilkat v11.6.0+

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.

Microsoft reference.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoTextCompare
    Handle hoConfig
    Boolean iSameText1
    Boolean iSameText2
    Handle hoEndpoint
    String sResourcePath
    Handle hoRest
    Variant vAzAuth
    Handle hoAzAuth
    Variant vConnection
    Handle hoConnection
    String sResponseText
    Handle hoResult
    Handle hoSeenMarkers
    String sMarker
    Boolean iMore
    Integer iPage
    Integer iDirectoryCount
    Integer iDirectoryIndex
    String sDirectoryName
    Boolean iSameText3
    Boolean iSameText4
    Handle hoDecodedDirectory
    Integer iFileCount
    Integer iFileIndex
    String sFileName
    Boolean iSameText5
    Boolean iSameText6
    Handle hoDecodedFile
    Boolean iSameText7
    String sTemp1
    Integer iTemp1
    Boolean bTemp1

    Move False To iSuccess

    //  StringBuilder compares text by value in every generated language.
    Get Create (RefClass(cComChilkatStringBuilder)) To hoTextCompare
    If (Not(IsComObjectCreated(hoTextCompare))) Begin
        Send CreateComObject of hoTextCompare
    End
    //  Assumes Chilkat is unlocked. See Global Unlock Sample.
    Move False To iSuccess
    Get Create (RefClass(cComChilkatJsonObject)) To hoConfig
    If (Not(IsComObjectCreated(hoConfig))) Begin
        Send CreateComObject of hoConfig
    End
    Set ComStrict Of hoConfig To True
    Get ComLoadFile Of hoConfig "qa_data/azure/storage.json" To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not load private Azure configuration."
        Procedure_Return
    End

    Send ComClear To hoTextCompare
    Get ComStringOf Of hoConfig "account" To sTemp1
    Get ComSetString Of hoTextCompare sTemp1 To iSuccess
    Get ComContentsEqual Of hoTextCompare "" True To iSameText1
    Get ComJsonTypeOf Of hoConfig "account" To iTemp1
    If ((iTemp1 <> 1) Or (iSameText1 = True)) Begin
        Showln "Supply the storage account name."
        Procedure_Return
    End

    //  access_key is the base64 account key, not a connection string or SAS.
    Send ComClear To hoTextCompare
    Get ComStringOf Of hoConfig "access_key" To sTemp1
    Get ComSetString Of hoTextCompare sTemp1 To iSuccess
    Get ComContentsEqual Of hoTextCompare "" True To iSameText2
    Get ComJsonTypeOf Of hoConfig "access_key" To iTemp1
    If ((iTemp1 <> 1) Or (iSameText2 = True)) Begin
        Showln "Supply the base64 account access key."
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatStringBuilder)) To hoEndpoint
    If (Not(IsComObjectCreated(hoEndpoint))) Begin
        Send CreateComObject of hoEndpoint
    End
    Get ComStringOf Of hoConfig "account" To sTemp1
    Get ComAppend Of hoEndpoint sTemp1 To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    Get ComAppend Of hoEndpoint ".file.core.windows.net" To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    //  resourcePath is already URL-encoded. Encode each path segment once when adapting it.
    //  Keep slash separators; names and paths are case-sensitive.
    Move "/examples/files" To sResourcePath
    Get Create (RefClass(cComChilkatRest)) To hoRest
    If (Not(IsComObjectCreated(hoRest))) Begin
        Send CreateComObject of hoRest
    End
    Set ComConnectTimeoutMs Of hoRest To 20000
    Set ComIdleTimeoutMs Of hoRest To 60000
    Get Create (RefClass(cComChilkatAuthAzureStorage)) To hoAzAuth
    If (Not(IsComObjectCreated(hoAzAuth))) Begin
        Send CreateComObject of hoAzAuth
    End
    Get ComStringOf Of hoConfig "account" To sTemp1
    Set ComAccount Of hoAzAuth To sTemp1
    Get ComStringOf Of hoConfig "access_key" To sTemp1
    Set ComAccessKey Of hoAzAuth To sTemp1
    Set ComService Of hoAzAuth To "File"
    Set ComScheme Of hoAzAuth To "SharedKey"
    Set ComXMsVersion Of hoAzAuth To "2026-04-06"
    Get pvComObject of hoAzAuth to vAzAuth
    Get ComSetAuthAzureStorage Of hoRest vAzAuth To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not configure Shared Key signing."
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatSocket)) To hoConnection
    If (Not(IsComObjectCreated(hoConnection))) Begin
        Send CreateComObject of hoConnection
    End
    Set ComRequireSslCertVerify Of hoConnection To True
    Set ComMaxReadIdleMs Of hoConnection To 60000
    Set ComMaxSendIdleMs Of hoConnection To 60000
    Get ComGetAsString Of hoEndpoint To sTemp1
    Get ComConnect Of hoConnection sTemp1 443 True 20000 To iSuccess
    If (iSuccess <> True) Begin
        Showln "TLS connection failed; inspect diagnostics privately."
        Procedure_Return
    End

    //  Do not replay a write automatically after losing its response.
    Get pvComObject of hoConnection to vConnection
    Get ComUseConnection Of hoRest vConnection False To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatXml)) To hoResult
    If (Not(IsComObjectCreated(hoResult))) Begin
        Send CreateComObject of hoResult
    End
    Set ComStrict Of hoResult To True
    Get ComAddQueryParam Of hoRest "restype" "directory" To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    Get ComAddQueryParam Of hoRest "comp" "list" To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    Get ComAddHeader Of hoRest "x-ms-file-extended-info" "true" To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    Get ComAddQueryParam Of hoRest "maxresults" "1000" To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatHashtable)) To hoSeenMarkers
    If (Not(IsComObjectCreated(hoSeenMarkers))) Begin
        Send CreateComObject of hoSeenMarkers
    End
    Move "" To sMarker
    Move True To iMore
    Move 0 To iPage
    While (iMore = True)
        If (iPage >= 1000) Begin
            Showln "Page limit reached; results are incomplete. Save the continuation marker."
            Procedure_Return
        End

        Get ComFullRequestNoBody Of hoRest "GET" sResourcePath To sResponseText
        Get ComLastMethodSuccess Of hoRest To bTemp1
        If (bTemp1 <> True) Begin
            Showln "Request did not complete; outcome may be uncertain."
            Procedure_Return
        End

        Get ComResponseStatusCode Of hoRest To iTemp1
        If (iTemp1 <> 200) Begin
            Get ComResponseStatusCode Of hoRest To iTemp1
            Showln "HTTP status: " iTemp1
            Get ComResponseHdrByName Of hoRest "x-ms-error-code" To sTemp1
            Showln "Azure error code: " sTemp1
            Get ComResponseHdrByName Of hoRest "x-ms-request-id" To sTemp1
            Showln "Request ID: " sTemp1
            //  Inspect any error body privately; do not log credentials, SAS URLs or payloads.
            Procedure_Return
        End

        Get ComLoadXml Of hoResult sResponseText To iSuccess
        If (iSuccess <> True) Begin
            Showln "Expected well-formed XML."
            Procedure_Return
        End

        Get ComTagEquals Of hoResult "EnumerationResults" To bTemp1
        If (bTemp1 <> True) Begin
            Showln "Unexpected XML response root."
            Procedure_Return
        End

        Get ComFindChild2 Of hoResult "Entries" To iSuccess
        If (iSuccess <> True) Begin
            Showln "Missing directory Entries element."
            Procedure_Return
        End

        Get ComNumChildrenHavingTag Of hoResult "Directory" To iDirectoryCount
        Move 0 To iDirectoryIndex
        While (iDirectoryIndex < iDirectoryCount)
            Set ComI Of hoResult To iDirectoryIndex
            Get ComGetChildContent Of hoResult "Directory[i]|Name" To sDirectoryName
            Send ComClear To hoTextCompare
            Get ComSetString Of hoTextCompare sDirectoryName To iSuccess
            Get ComContentsEqual Of hoTextCompare "" True To iSameText3
            If (iSameText3 <> True) Begin
                Send ComClear To hoTextCompare
                Get ComGetChildAttrValue Of hoResult "Directory[i]|Name" "Encoded" To sTemp1
                Get ComSetString Of hoTextCompare sTemp1 To iSuccess
                Get ComContentsEqual Of hoTextCompare "true" True To iSameText4
                If (iSameText4 = True) Begin
                    Get Create (RefClass(cComChilkatStringBuilder)) To hoDecodedDirectory
                    If (Not(IsComObjectCreated(hoDecodedDirectory))) Begin
                        Send CreateComObject of hoDecodedDirectory
                    End
                    Get ComAppend Of hoDecodedDirectory sDirectoryName To iSuccess
                    If (iSuccess <> True) Begin
                        Showln "Could not prepare the request."
                        Procedure_Return
                    End

                    Get ComDecode Of hoDecodedDirectory "url" "utf-8" To iSuccess
                    If (iSuccess <> True) Begin
                        Showln "Could not prepare the request."
                        Procedure_Return
                    End

                    Get ComGetAsString Of hoDecodedDirectory To sDirectoryName
                End

                Showln "Directory: " sDirectoryName
                Get ComGetChildContent Of hoResult "Directory[i]|FileId" To sTemp1
                Showln "File ID: " sTemp1
            End

            Move (iDirectoryIndex + 1) To iDirectoryIndex
        Loop

        Get ComNumChildrenHavingTag Of hoResult "File" To iFileCount
        Move 0 To iFileIndex
        While (iFileIndex < iFileCount)
            Set ComI Of hoResult To iFileIndex
            Get ComGetChildContent Of hoResult "File[i]|Name" To sFileName
            Send ComClear To hoTextCompare
            Get ComSetString Of hoTextCompare sFileName To iSuccess
            Get ComContentsEqual Of hoTextCompare "" True To iSameText5
            If (iSameText5 <> True) Begin
                Send ComClear To hoTextCompare
                Get ComGetChildAttrValue Of hoResult "File[i]|Name" "Encoded" To sTemp1
                Get ComSetString Of hoTextCompare sTemp1 To iSuccess
                Get ComContentsEqual Of hoTextCompare "true" True To iSameText6
                If (iSameText6 = True) Begin
                    Get Create (RefClass(cComChilkatStringBuilder)) To hoDecodedFile
                    If (Not(IsComObjectCreated(hoDecodedFile))) Begin
                        Send CreateComObject of hoDecodedFile
                    End
                    Get ComAppend Of hoDecodedFile sFileName To iSuccess
                    If (iSuccess <> True) Begin
                        Showln "Could not prepare the request."
                        Procedure_Return
                    End

                    Get ComDecode Of hoDecodedFile "url" "utf-8" To iSuccess
                    If (iSuccess <> True) Begin
                        Showln "Could not prepare the request."
                        Procedure_Return
                    End

                    Get ComGetAsString Of hoDecodedFile To sFileName
                End

                Showln "File: " sFileName
                Get ComGetChildContent Of hoResult "File[i]|FileId" To sTemp1
                Showln "File ID: " sTemp1
                Get ComGetChildContent Of hoResult "File[i]|Properties|Content-Length" To sTemp1
                Showln "Size: " sTemp1
            End

            Move (iFileIndex + 1) To iFileIndex
        Loop

        Get ComGetParent2 Of hoResult To iSuccess
        If (iSuccess <> True) Begin
            Showln "Could not return to enumeration root."
            Procedure_Return
        End

        Get ComGetChildContent Of hoResult "NextMarker" To sMarker
        Move (iPage + 1) To iPage
        Send ComClear To hoTextCompare
        Get ComSetString Of hoTextCompare sMarker To iSuccess
        Get ComContentsEqual Of hoTextCompare "" True To iSameText7
        If (iSameText7 = True) Begin
            Move False To iMore
        End
        Else Begin
            Get ComContains Of hoSeenMarkers sMarker To bTemp1
            If (bTemp1 = True) Begin
                Showln "Repeated marker; results are incomplete."
                Procedure_Return
            End

            Get ComAddInt Of hoSeenMarkers sMarker 1 To iSuccess
            If (iSuccess <> True) Begin
                Showln "Could not prepare the request."
                Procedure_Return
            End

            If (iPage > 1) Begin
                Get ComRemoveQueryParam Of hoRest "marker" To iSuccess
                If (iSuccess <> True) Begin
                    Showln "Could not prepare the request."
                    Procedure_Return
                End

            End

            Get ComAddQueryParam Of hoRest "marker" sMarker To iSuccess
            If (iSuccess <> True) Begin
                Showln "Could not prepare the request."
                Procedure_Return
            End

            Get ComDisconnect Of hoRest 10 To iSuccess
            Get ComGetAsString Of hoEndpoint To sTemp1
            Get ComConnect Of hoConnection sTemp1 443 True 20000 To iSuccess
            If (iSuccess <> True) Begin
                Showln "TLS reconnection failed."
                Procedure_Return
            End

            Get pvComObject of hoConnection to vConnection
            Get ComUseConnection Of hoRest vConnection False To iSuccess
            If (iSuccess <> True) Begin
                Showln "Could not prepare the request."
                Procedure_Return
            End

        End

    Loop

    Showln "Directory listing complete."


End_Procedure