83Plus:Software:usb8x/Asm Interface/MSD/DOS getNextFile
From WikiTI
Jump to navigationJump to search
Synopsis
Name: DOS_getNextFile
Minimum usb8x version: 0.10
Gets first/next file/folder in specified directory.
Inputs
- HL is the starting cluster of the directory (obtained with [[../FAT_getStartingCluster|FAT_getStartingCluster]])
- BC is the current entry number of a file (pass -1 on first call to this function to get the first file)
Outputs
- HL points to the directory entry of the next file
- BC is the entry number of the next file
- C set if no more files are found
Destroys
- AF, BC, DE, HL
Notes
If you want to list files/folders in a specified directory, such as for a file explorer interface, this is the function you want to use.
Example code to list all files/folders in the "test" directory, which is in the root directory:
dir_cluster equ statVars ;2 bytes, starting cluster of directory
file_name equ statVars+2 ;13 bytes, ASCIIZ filename
...
ld hl,0
ld (curRow),hl
ld hl,sDirectory
U_CALL FAT_getStartingCluster
ld (dir_cluster),hl
ld bc,-1
listLoop:
ld hl,(dir_cluster)
U_CALL DOS_getNextFile
jr c,listDone
ld de,file_name
push bc
U_CALL FAT_nameConvertFrom11
B_CALL PutS
B_CALL NewLine
pop bc
jr listLoop
listDone:
...
sDirectory: DB "/test",0
If you are writing an application, you must copy the strings you use to RAM first, or else usb8x will not be able to see them.
See Also
- [[../FAT_getStartingCluster|FAT_getStartingCluster]] - Get starting cluster of specified directory