File_ChDir()

Parent Previous Next

File_ChDir(pFileName), Bit


pFileName: The name of the directory to switch to. The directory name should be 8 characters or less, including the dot (.) and extension (if any). Example: "MyFolder", "Documents".


Result Bit: The result is a single bit indicating success or failure.

1: Success — the directory has been changed successfully.

0: Failure — the directory change was unsuccessful.


Change Directory


The File_ChDir() command allows you to change the current working directory to the specified directory. This is useful when you want to navigate between directories on the SD card for file operations such as reading or writing files.


Example:

File_ChDir("MyFolder")


When to Use:

File_ChDir() is used when you want to navigate between directories on the SD card. It must be called before performing file operations like creating or reading files from the new directory.

• Ensure you handle errors (like trying to access a non-existent directory) when using this command to avoid unexpected issues.


Important Notes:

• Before calling File_ChDir(), you need to close any open files using File_Close() to ensure proper functioning.

• If you try to change to a non-existent directory or a directory that is in use, the operation will fail, and the result will be 0.


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: Maximize Your Documentation Efficiency with a Help Authoring Tool