Jump to main content

##

# 1.2.7.4.32 SYS_FS_CurrentWorkingDirectoryGet Function

## C

    SYS_FS_RESULT SYS_FS_CurrentWorkingDirectoryGet
    (
        char *buff,
        uint32_t len
    );

## Summary

Gets the current working directory

## Description

This function gets the current working directory path along with the working drive.

## Precondition

At least one disk must be mounted.

## Parameters

Param | Description
--- | ---
buff | Pointer to a buffer which will contain the name of the current working directory and drive, once the function completes.
len | Size of the buffer.

## Returns

SYS_FS_RES_SUCCESS - Get current working directory operation was successful.

SYS_FS_RES_FAILURE - Get current working directory operation was unsucessful. The reason for the failure can be retrieved with SYS_FS_Error.

## Example

    SYS_FS_RESULT res;
    char buffer[16];

    switch(appState)
    {
        case TRY_MOUNT:
        {
            if(SYS_FS_Mount("/dev/mmcblka1", "/mnt/myDrive", FAT, 0, NULL) != SYS_FS_RES_SUCCESS)
            {
                // Failure, try mounting again
            }
            else
            {
                // Mount was successful. Create a directory.
                appState = CREATE_DIR;
            }
            break;
        }

        case CREATE_DIR:
        {
            res = SYS_FS_DirectoryMake("Dir1");
            if(res == SYS_FS_RES_FAILURE)
            {
                // Directory creation failed
                appState = ERROR;
            }
            else
            {
                // Directory creation was successful. Change to the new
                // directory.
                appState = CHANGE_DIR;
            }
            break;
        }

        case CHANGE_DIR:
        {
            res = SYS_FS_DirectoryChange("Dir1");
            if(res == SYS_FS_RES_FAILURE)
            {
                // Directory change failed
                appState = ERROR;
            }
            else
            {
                // Directory change was successful. Get current working
                // directory
                appState = GET_CWD;
            }
            break;
        }

        case GET_CWD:
        {
            res = SYS_FS_CurrentWorkingDirectoryGet(buffer, 15);
            if(res == SYS_FS_RES_FAILURE)
            {
                // Get current directory operation failed
                appState = ERROR;
            }
            break;
        }
    }

## Remarks

None.