File_ChDirUp()

Parent Previous Next

File_ChDirUp(), Bit


Result Bit: A single bit indicating success or failure.

1: Success — the directory has been changed to the parent directory.

0: Failure — the directory change was unsuccessful (e.g., if you're already at the root directory).


Change to Parent Directory


The File_ChDirUp() command allows you to change the current working directory to the parent directory of the current directory. This is useful for navigating upwards through the directory structure on the SD card.


Example:

File_ChDirUp()


Purpose:

• To move the current working directory up one level to the parent directory.

• After calling this command, all subsequent file operations will be performed within the parent directory of the current directory.


Notes:

• Before calling File_ChDirUp(), make sure to close any open files using File_Close() to ensure the proper functioning of the command.

• If the current directory is the root directory (i.e., the topmost directory), you cannot go further up, and the command will fail, returning 0.

• This function is often used for navigating back up the directory tree when browsing through nested folders.


TftSetUp(0)                                                                                 'Set screen

TftResetScreen(BLACK)                                                                       'Reset screen

TftSetSndFont(0,0)                                                                          'Set Font0

While File_Init() <> cErrOK : Wend                                                          'Initialize SD Card

TftPrintSndString("Sd Initialization OK",1,0,0,1,GREEN,BLACK,0)                             'Confirm Initialize SD Card

DisplayFolderFile(28)                                                                       'Call file/folder list Proc, set display row 28

If File_ChDir("Fol1") = 1 Then                                                              'Change current folder to Fol1

    TftPrintSndString("Change to Fol1 OK",1,0,1,1,GREEN,BLACK,0)                            'Confirm change folder To Fol1

    DisplayFolderFile(20)                                                                   'Call file/folder list Proc, Set display row 20

Else

    TftPrintSndString("Change to Fol1 Fail",1,0,1,1,GREEN,BLACK,0)                          'Folder change fail

EndIf

If File_ChDirUp() = 1 Then                                                                  'Return to parent directory

    TftPrintSndString("Change to Parent OK",1,0,2,1,GREEN,BLACK,0)                          'Confirm change to parent folder

    DisplayFolderFile(12)                                                                   'Call file/folder list Proc, Set display row 12

Else

    TftPrintSndString("Change to Parent Fail",1,0,2,1,GREEN,BLACK,0)                        'Folder change to parent fail

EndIf

End  


Proc DisplayFolderFile(wY As Word)

    bCounter = wY

    File_ListReset()                                                                        'Reset file/folder counter

    Do       

        Clear sString                                                                                   

        sString = File_ListDir()                                                            'Loop through folder names

        If sString = 0 Then Break                                                           'Break if end of list

        TftPrintSndString(sString,1,0,bCounter,1,GREEN,BLACK,0)                             'Print folder name

        Dec bCounter                                                                        'Move to next print line

    Loop

    bCounter = wY                                                                           'Vertical print counter

    File_ListReset()                                                                        'Reset file/folder counter

    Do                                                                                      'Loop through file names

        Clear sString

        sString = File_ListFile()

        If sString = 0 Then Break                                                           'Break if end of list

        TftPrintSndString(sString,1,20,bCounter,1,WHITE,BLACK,0)                            'Print folder name

        Dec bCounter                                                                        'Move to next print line

    Loop

EndProc






Created with the Personal Edition of HelpNDoc: Single source CHM, PDF, DOC and HTML Help creation