If you are using SDFS from MeLabs here is a snippet that might help.
Code:
SDOPEN_W:
' Open a file for write
	FAT_mode = "A"		' Write mode
	Gosub FSfopen		' Open file pointed to by Byte array FAT_FileName

  Serout2 PORTC.6, 16572, ["Open for write Error: ", Dec FAT_error, $d, $a]

Serout2 PORTC.6, 16572, [ "FILE NAME  ", STR FAT_FileName\11, $d, $a]
Serout2 PORTC.6, 16572, [ "DISK_fat  ", Dec DISK_fat, $d, $a]
Serout2 PORTC.6, 16572, [ "DISK_buffer  ", Dec DISK_buffer, $d, $a]
Serout2 PORTC.6, 16572, [ "SDC_sector_addr  ", Dec SDC_sector_addr, $d, $a]
Serout2 PORTC.6, 16572, [ "FAT_ccls   ", Dec FAT_ccls, $d, $a]
Serout2 PORTC.6, 16572, [ "LAST_CLUSTER ", Dec LAST_CLUSTER, $d, $a]
Serout2 PORTC.6, 16572, [ "FAT_c  ", Dec FAT_c, $d, $a]
Serout2 PORTC.6, 16572, [ "DISK_maxcls:  ", Dec DISK_maxcls, $d, $a]