Change the current working directory.

Syntax

int f_chdir(
  const char *path
);

Parameters

path
[in] A pointer to a string that represents the path of a directory.

Return value

Returns 0 if the function succeeds, non-zero value otherwise.

Remarks

Change the current working directory to the directory specified by path.
The current working directory is the starting point for interpreting relative path that do not start with "/".
The initial value of the current working directory is "1:/" (root directory).

Note:

The directory specified as the current working directory cannot be deleted.

Requirements

Header file:
lib.h
Library file:
libSTARTUPOPH5000.a

Sample

#include <stdio.h>
#include "lib.h"

void main(void)
{
    // Current working directory(CWD) = "1:/"

    f_mkdir("1:/DIR1");       // absolute path: Create "1:/DIR1"
    f_mkdir("1:/DIR1/DIR2");  // absolute path: Create "1:/DIR1/DIR2"

    f_mkdir("DIR3");          // relative path: Create "1:/DIR3"

    f_chdir("DIR3");          // relative path: Change CWD to "1:/DIR3"

    f_mkdir("DIR4");          // relative path: Create "1:/DIR3/DIR4"

    remove("DIR4");           // relative oath: Delete "1:/DIR3/DIR4"

    f_chdir("1:/");           // absolute path: Change CWD to"1:/"

    remove("1:/DIR3");        // absolute path: Delete "1:/DIR3"

    f_chdir("/DIR1");         // absolute path without drive identifier: Change CWD to "1:/DIR1"

    remove("DIR2");           // relative path: Delete "1:DIR1/DIR2"

    f_chdir("/");             // absolute path without drive identifier: Change CWD to "1:/"

    remove("/DIR1");          // absolute path without drive identifier: Delete "1:DIR1"

    while(1){
        Idle();
    }
}

See also

Last updated: 2020/11/15