Create a Directory
Method name:
makeDir
Creates a directory but does not create leading path segments. (See Create a Directory Along With Leading Paths if you want to create any non-existant leading paths for the new directory.)
If the directory is successfully created, the system sets the parent directory’s mtime (last modified time) to the current system time.
A directory cannot contain a file and a sub-directory with the same name.
Create a Directory Using Named Parameters
JSON
1{2 "method": "makeDir",3 "id": 1,4 "params": {5 "token": "9dda5a3a-cb4d-48ee-9e4e-bce49f6bf7dc",6 "path": "/house2"7 },8 "jsonrpc": "2.0"9}
Create a Directory Using Positional Parameters
Positional parameters must be applied in the same order shown in the named parameters sample. Example:
JSON
1{2 "method": "makeDir",3 "id": 1,4 "params": [5 "9dda5a3a-cb4d-48ee-9e4e-bce49f6bf7dc",6 "/MakeDirPosParamTest2"7 ],8 "jsonrpc": "2.0"9}
Parameter Descriptions
Parameter Name | Type | Description |
---|---|---|
token | str | Valid token from a call to login (JSON-RPC interface) or /account/login (HTTP interface). See Log In Using JSON-RPC and Log in Using the HTTP Interface, respectively. |
path | str | The directory to create. If the directory has parent paths that do not exist, the method call fails. For example if you pass /a/b for path and a does not exist then the call fails. To create parent paths, see Create a Directory Along With Leading Paths. You can’t create a directory if the parent directory contains a file with the same name as the directory you want to create. Example: if file b exists in directory a then you can’t create a directory called b in directory a. |
You can create directories with any white space in the path, including spaces, new lines, carriage returns and horizontal tabs.
You must use the UNIX/Linux path separator
/
. If you use the Windows path separator \
it becomes part of the name.If you omit the path separator, the directory is created under the root.
Path segments can contain a maximum of 4096 bytes. For more information, see Path Segment and File Name Limitations.|
Return Codes
- 0: success
- -1: malformed path
- -2: path exists. Parent directory already contains a file with the same name as the directory you attempted to create.
- -3: parent path does not exist
- -4: internal error
- -5: internal error
- -6: permission denied. Caller’s uid does not exist or does not have permissions to path.
- -8: invalid or malformed path
- -10001: invalid token
For a list of error codes not specific to
makeDir
, see Global Error Codes.Response Data
Returns only the codes discussed in Return Codes. Does not return any data structures.
Python Sample Requests
Create
images
directory:Python
1>>> api.makeDir(token, '/images')20
Create a Directory Along With Leading Paths
Method name:
makeDir2
Creates a directory along with any parent paths that do not already exist.
If the directory is successfully created, the system sets the parent directory’s mtime (last modified time) to the current system time.
A directory cannot contain a file and a sub-directory with the same name.
Create a Directory Using Named Parameters
JSON
1{2 "method": "makeDir2",3 "id": 3,4 "params": {5 "token": "613c28c6-6a1b-4938-9d5a-3a1e7feb98c6",6 "path": "/climate/asia"7 },8 "jsonrpc": "2.0"9}
Create a Directory Using Positional Parameters
Positional parameters must be applied in the same order shown in the named parameters sample. Example:
JSON
1{2 "method": "makeDir2",3 "id": 2,4 "params": [5 "0881fb22-f1cd-43a4-a7f2-f9ccb8fa55f9",6 "/climate/asia"7 ],8 "jsonrpc": "2.0"9}
Parameter Descriptions
Parameter Name | Type | Description |
---|---|---|
token | str | Valid token from a call to login (JSON-RPC interface) or /account/login (HTTP interface). See Log In Using JSON-RPC and Log in Using the HTTP Interface, respectively. |
path | str | The directory to create. If the directory has parent paths that do not exist, the method call fails. For example if you pass /a/b for path and a does not exist then the call fails. To create parent paths, see Create a Directory Along With Leading Paths. You can’t create a directory if the parent directory contains a file with the same name as the directory you want to create. Example: if file b exists in directory a then you can’t create a directory called b in directory a. |
You can create directories with any white space in the path, including spaces, new lines, carriage returns and horizontal tabs.
You must use the UNIX/Linux path separator
/
. If you use the Windows path separator \
it becomes part of the name.If you omit the path separator, the directory is created under the root.
Path segments can contain a maximum 4096 bytes. For more information, see Path Segment and File Name Limitations.
Return Codes
- 0: success
- -1: malformed path
- -2: path exists. Parent directory already contains a file with the same name as the directory you attempted to create.
- -3: parent path does not exist
- -4: internal error
- -5: internal error
- -6: permission denied. Caller’s uid does not exist or does not have permissions to path.
- -8: invalid or malformed path
- -10001: invalid token
For a list of error codes not specific to
makeDir2
, see Global Error Codes.Response Data
Returns only the codes discussed in Return Codes. Does not return any data structures.
Python Sample Requests
The EMEA directory does not currently exist. Create it along with the flowers directory.
JSON
1>>> api.makeDir2(token, 'EMEA/flowers')20
Delete a Directory
Method name:
deleteDir
Deletes a directory. If the directory is successfully deleted, the system sets the parent directory’s mtime (last modification time) to the current system time.
Although Edgio provides APIs for deleting and renaming a directory, you can do so only if the directory contains no files or sub-directories. This is because the required background processes, such as re-applying policies and pushing maps out to Bricks, could potentially have a significant impact on the Origin Storage platform, causing latency in other operations.
If you are having trouble deleting or managing content with the existing supported management tools or via the API, please contact your account manager who will engage the Edgio Advanced Services team to work with you to achieve the desired results (additional charges may apply).
Delete a Directory Using Named Parameters
JSON
1{2 "method": "deleteDir",3 "id": 2,4 "params": {5 "token": "c880eae3-49bd-4dbd-91c4-05eaa0a3c598",6 "path": "/tempDelete"7 },8 "jsonrpc": "2.0"9}
Delete a Directory Using Positional Parameters
Positional parameters must be applied in the same order shown in the named parameters sample. Example:
JSON
1{2 "method": "deleteDir",3 "id": 1,4 "params": [5 "024e3b1e-d808-4f67-a7b8-5bf432169721",6 "/tempDelete"7 ],8 "jsonrpc": "2.0"9}
Parameter Descriptions
Parameter Name | Type | Description |
---|---|---|
token | str | Valid token from a call to login (JSON-RPC interface) or /account/login (HTTP interface). See Log In Using JSON-RPC and Log in Using the HTTP Interface, respectively. |
path | str | Directory to delete |
Return Codes
- 0: success
- -1: directory does not exist
- -5: other unspecified error
- -6: permission denied. Caller’s user ID does not exist, or caller’s user ID does not have permissions to path.
- -7: operation not permitted. The directory contains sub-directories or files.
- -10001: invalid token
Response Data
Returns only the codes discussed in Return Codes. Does not return any data structures.
Python Sample Requests
Delete the temp directory:
Python
1>>> api.deleteDir(token, '/temp')20
Attempt to delete a directory with sub-directories:
Python
1# First create the directory.2>>> api.makeDir2(token, '/has-sub-dirs/sub-dir')304# Now attempt to delete it.5>>> api.deleteDir(token, '/has-sub-dirs')6-7
List Directories
Method name:
listDir
Lists directories that are direct children of a given path. Includes the ability to limit the number of directories returned as well as the ability to include directory details such as creation and modification time. The method is not recursive and operates only on the given path.
List Directories Using Named Parameters
JSON
1{2 "method": "listDir",3 "id": 1,4 "params": {5 "token": "fd64425a-20b2-4979-bff0-a6923f5325fb",6 "path": "/",7 "pageSize": 1,8 "cookie": 0,9 "stat": true10 },11 "jsonrpc": "2.0"12}
List Directories Using Positional Parameters
Positional parameters must be applied in the same order shown in the named parameters sample. Example:
JSON
1{2 "method": "listDir",3 "id": 0,4 "params": [5 "c24929c1-2aaf-4c94-975b-bc886a393869",6 "/",7 5,8 0,9 true10 ],11 "jsonrpc": "2.0"12}
Parameter Descriptions
Parameter Name | Type | Description |
---|---|---|
token | str | Valid token from a call to login (JSON-RPC interface) or /account/login (HTTP interface). See Log In Using JSON-RPC and Log in Using the HTTP Interface, respectively. |
path | str | Directory path whose sub-directories you want to list. |
pageSize | int | Optional The number of directories to return from a call to the method. Must be less than or equal to 10000. Defaults to 100. |
cookie | uint64 | Optional On return, indicates whether additional directories can be returned with subsequent calls to the function. Pass 0 the first time you call the function. For all subsequent calls, pass the cookie value returned from the prior call. Defaults to 0. |
stat | bool | Optional Include file details in output. Pass True or False . See Response Data for more information.Defaults to False . |
Return Codes
- 0: success
- -1: path does not exist
- -11: invalid cookie
- -12: invalid pageSize
- -10001: invalid token
For a list of error codes not specific to
listDir
, see Global Error Codes.Response Data
When the stat parameter is set to False, the method returns an object with the following data:
- code: (int) return code
- cookie: (uint64) indicates whether additional directories can be returned with subsequent calls to the function. Non-zero value: additional directories are available. Zero value: no more directories are available.
- list: array of directory objects. Data for each object is:
- name: (str) directory name
- type: (int). Always 1 (directory)
The order in which directories are returned is non-deterministic. Results are not sorted.
Example:
JSON
1{2 "code": 0,3 "cookie": 2,4 "list": [5 {6 "name": "picture",7 "type": 18 },9 {10 "name": "video",11 "type": 112 }13 ]14}
When the stat parameter is set to True, the following additional parameters will be returned under a stat key for each directory listed:
- ctime: (int) creation time in seconds since epoch
- gid: (int) group ID of user that created the directory
- mtime: (int) last modification time in seconds since epoch
- uid: (int) ID of user that created the directory
Example:
JSON
1{2 "code": 0,3 "cookie": 1,4 "list": [5 {6 "stat": {7 "uid": 12020,8 "gid": 100,9 "ctime": 1423257988,10 "mtime": 142325798811 },12 "name": "picture",13 "type": 114 }15 ]16}
Python Sample Requests
Pass only required arguments:
Python
1api.listDir(token, '/')23 { "code": 0,4 "cookie": 3,5 "list": [6 {7 "name": "picture",8 "type": 19 },10 {11 "name": "video",12 "type": 113 },14 {15 "name": "dir10",16 "type": 117 }18 ]19}
Details returned when you pass True for the stat parameter:
Python
1api.listDir(token, '/', 1, 0, True)23{4 "code": 0,5 "cookie": 1,6 "list": [7 {8 "stat": {9 "uid": 12020,10 "gid": 100,11 "ctime": 1423257988,12 "mtime": 142325798813 },14 "name": "picture",15 "type": 116 }17 ]18}
Loop through all directories in chunks of four and print directory names.
Python
1# User-defined variables2dir = '/'3pageSize = 4456def printDirs( dirList ):7 global hasDirs8 for ( item ) in dirList:9 hasDirs = True10 print item['name']1112hasDirs = False13results = api.listDir( token, dir, pageSize, False )1415print 'Sub-directories in directory "' + dir + '":'16printDirs( results['list'] )17cookie = results['cookie']1819while ( cookie > 0 ):20 results = api.listDir( token, dir, pageSize, cookie, False )21 printDirs( results['list'] )22 cookie = results['cookie']2324if not hasDirs:25 print '**No sub-directories'