List a folder's contents
Short answer
List a folder's contents with GET /v2/files/readdir. It will return the filename, mimetype, content type and file size. It will also return any folders that exist. A page of up to 100 results will be returned - use the 'continuation' field to request additional pages. Each call needs a bearer token and counts towards your hourly API limit.
After reading this you will know
- How to list a folder's contents
- Which parameters it takes
- Sample code in 9 languages and a sample answer
This command needs a bearer token and counts towards your hourly limit.
Read folder contents
Section titled “Read folder contents”https://api.sirv.com/v2/files/readdir
Use this API method to get a list of all the files/folders within a folder.
It will return the filename, mimetype, content type and file size. It will also return any folders that exist.
A page of up to 100 results will be returned - use the ‘continuation’ field to request additional pages.
Query parameters
| Name | Type | Required | Example | Description |
|---|---|---|---|---|
dirname | string | Yes | /REST API Examples | Path of the folder to list, starting with /. |
continuation | string | No | Send it to get next page of results |
Example request
// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variableconst res = await fetch('https://api.sirv.com/v2/files/readdir?dirname=%2FREST%20API%20Examples', { method: 'GET', headers: { authorization: `Bearer ${process.env.SIRV_TOKEN}` },});console.log(res.status, await res.text());import requests
res = requests.get( 'https://api.sirv.com/v2/files/readdir?dirname=%2FREST%20API%20Examples', headers={'authorization': 'Bearer BEARER_TOKEN'},)print(res.status_code, res.text)curl --request GET \ --url 'https://api.sirv.com/v2/files/readdir?dirname=%2FREST%20API%20Examples' \ --header 'authorization: Bearer BEARER_TOKEN'import java.net.URI;import java.net.http.HttpClient;import java.net.http.HttpRequest;import java.net.http.HttpResponse;
HttpClient client = HttpClient.newHttpClient();HttpRequest request = HttpRequest.newBuilder(URI.create("https://api.sirv.com/v2/files/readdir?dirname=%2FREST%20API%20Examples")) .header("authorization", "Bearer BEARER_TOKEN") .method("GET", HttpRequest.BodyPublishers.noBody()) .build();HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());System.out.println(response.statusCode() + " " + response.body());using System.Net.Http.Headers;
using var client = new HttpClient();var request = new HttpRequestMessage(new HttpMethod("GET"), "https://api.sirv.com/v2/files/readdir?dirname=%2FREST%20API%20Examples");request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "BEARER_TOKEN");var response = await client.SendAsync(request);Console.WriteLine($"{(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}");<?php$ch = curl_init('https://api.sirv.com/v2/files/readdir?dirname=%2FREST%20API%20Examples');curl_setopt_array($ch, [ CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => ['authorization: Bearer BEARER_TOKEN'], CURLOPT_RETURNTRANSFER => true,]);echo curl_exec($ch);package main
import ( "fmt" "io" "net/http")
func main() { req, _ := http.NewRequest("GET", "https://api.sirv.com/v2/files/readdir?dirname=%2FREST%20API%20Examples", nil) req.Header.Set("authorization", "Bearer BEARER_TOKEN") res, err := http.DefaultClient.Do(req) if err != nil { panic(err) } defer res.Body.Close() out, _ := io.ReadAll(res.Body) fmt.Println(res.Status, string(out))}require 'net/http'
uri = URI('https://api.sirv.com/v2/files/readdir?dirname=%2FREST%20API%20Examples')req = Net::HTTP::Get.new(uri)req['authorization'] = 'Bearer BEARER_TOKEN'res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }puts res.code, res.bodyimport Foundation
var request = URLRequest(url: URL(string: "https://api.sirv.com/v2/files/readdir?dirname=%2FREST%20API%20Examples")!)request.httpMethod = "GET"request.setValue("Bearer BEARER_TOKEN", forHTTPHeaderField: "authorization")let (data, response) = try await URLSession.shared.data(for: request)print((response as! HTTPURLResponse).statusCode, String(decoding: data, as: UTF8.self))Example response
{ "contents": [ { "filename": "aurora.jpg", "mtime": "2026-02-23T10:22:34.659Z", "contentType": "image/jpeg", "size": 260864, "isDirectory": false, "meta": { "width": 2500, "height": 1667, "duration": 0 } }, { "filename": "aurora3.jpg", "mtime": "2020-11-18T19:55:13.459Z", "contentType": "image/webp", "size": 201846, "isDirectory": false, "meta": { "width": 2500, "height": 1667, "duration": 0 } } ]}