Help Center/ MapReduce Service/ API Reference (Ankara Region)/ API V2/ Cluster HDFS File API/ Obtaining the List of Files from a Specified Directory
Updated on 2024-11-29 GMT+08:00

Obtaining the List of Files from a Specified Directory

Function

This API is used to obtain the list of files from a specified directory in an MRS cluster.

URI

GET /v2/{project_id}/clusters/{cluster_id}/files
Table 1 URI parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Explanation

Project ID. For details about how to obtain the project ID, see Obtaining a Project ID.

Constraints

N/A

Value range

The value must consist of 1 to 64 characters. Only letters and digits are allowed.

Default value

N/A

cluster_id

Yes

String

Explanation

Cluster ID. If this parameter is specified, the latest metadata of the cluster that has been patched will be obtained. For details about how to obtain the cluster ID, see Obtaining a Cluster ID.

Constraints

N/A

Value range

The value can contain 1 to 64 characters, including only letters, digits, underscores (_), and hyphens (-).

Default value

N/A

Table 2 Query parameters

Parameter

Mandatory

Type

Description

path

Yes

String

Explanation

File category. For example, to access the /tmp/test directory, the value must be a directory. The URI is /v2/{project_id}/clusters/{cluster_id}/files?path=%2Ftmp %2Ftest.

Constraints

N/A

Value range

A single-level directory must comply with the following rules:

  • The directory path cannot be left blank.
  • The value cannot start or end with a period (.).
  • The value cannot contain the following characters: /:*?"<>|\;&,'`!{}[]$%+
  • The value cannot exceed 255 characters.

Default value

N/A

offset

No

String

Explanation

Pagination parameter. The file list is queried from the offset.

Constraints

N/A

Value range

N/A

Default value

1

limit

No

String

Explanation

Maximum number of records displayed on a page.

Constraints

N/A

Value range

≤1000

Default value

100

sort_key

No

String

Explanation

Attribute used for sorting the list.

Constraints

N/A

Value range

  • path_suffix: file or directory name
  • length: file size
  • modification_time: modification time

Default value

path_suffix

order

No

String

Explanation

List sorting method.

Constraints

N/A

Value range

  • desc: descending order
  • asc: ascending order

Default value

desc

Request Parameters

None

Response Parameters

Table 3 Response parameters

Parameter

Type

Description

total_count

Integer

Explanation

The total number of files, which is irrelevant to pagination.

Value range

N/A

files

Array of FileStatusV2 objects

Explanation

File list. For details, see Table 4.

Table 4 FileStatus parameters

Parameter

Type

Description

path_suffix

String

Explanation

The file name extension in the current directory. For example, if you obtain the /tmp/test file in the /tmp directory, the value of path_suffix is test.

Value range

N/A

owner

String

Explanation

File owner.

Value range

N/A

group

String

Explanation

File owner group.

Value range

N/A

permission

String

Explanation

Permission information.

Value range

N/A

replication

Integer

Explanation

Number of replicas.

Value range

N/A

block_size

Integer

Explanation

Block size.

Value range

N/A

length

Integer

Explanation

File length.

Value range

N/A

type

String

Explanation

File type

Value range

  • FILE: file
  • DIRECTORY: directory

children_num

Integer

Explanation

Number of files in the directory.

Value range

N/A

access_time

Long

Explanation

File access time.

Value range

N/A

modification_time

Long

Explanation

File modification time

Value range

N/A

Example Request

Obtain the list of files from a specified directory.

GET /v2/{project_id}/clusters/{cluster_id}/files?path={directory}&offset={offset}&limit={limit}&sort_key={sort_key}&order={order}

Example Response

Status code: 200

Obtaining the file list of a specified directory is successful.
{
    "total_count": 2,
    "files": [
        {
            "access_time": 0,
            "block_size": 0,
            "children_num": 0,
            "group": "hadoop",
            "length": 0,
            "modification_time": 1587179516623,
            "owner": "hdfs",
            "path_suffix": "app-logs",
            "permission": "777",
            "replication": 0,
            "type": "DIRECTORY"
        },
        {
            "access_time": 1587267212761,
            "block_size": 134217728,
            "children_num": 0,
            "group": "hadoop",
            "length": 23666188,
            "modification_time": 1587222156003,
            "owner": "root",
            "path_suffix": "data-m-00000",
            "permission": "644",
            "replication": 3,
            "type": "FILE"
        }
    ]
}

Status Codes

See Status Codes.

Error Codes

See Error Codes.