Example: chdir

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