Share this page

# chdir

File Manipulation Functions

Changes the current directory to the given path. (Windows only)

    int chdir( const char *path);

path | The target path.

For chdir details, refer to your C language documentation.

## Return Values

This function returns zero upon success and (-1) for failure.

## Example

The following example uses chdir to change the current directory to DirString. It creates a new directory xyz under DirString and then changes directory to it.

        #ifdef unix
            char DirString[] = "/tmp";
            char NewDir[] = "/tmp/xyz";
        #else
            char DirString[] = "C:\\";
            char NewDir[] = "C:\\xyz";
        #endif

        // Change the current working directory to DirString

        if (chdir(DirString)) {
            lr_output_message ("Unable to locate directory: %s", DirString);
            return -1;
        }
        else
            lr_output_message ("Changed directory to %s", DirString);

        // Create a directory under root called xyz and make it the current dir

        if (mkdir(NewDir)) {
            lr_output_message ("Create directory %s failed", NewDir);
            return -1;
        }

        if (chdir(NewDir)) {
            lr_output_message ("Unable to change to dir %s", NewDir);
            return -1;
        }
        else
            lr_output_message ("Changed to new dir %s", NewDir);

    Example: Output:
    Action.c(18): Changed dir to C:\
    Action.c(33): Changed to new dir C:\xyz

Tips to improve your search results... VuGen Function Reference Version 26.1 Function Reference 26.1 All View Local Help Center View Online Help Center Version: