Opening multiple files with fsrw 2.6

in Propeller 1
I have been using fsrw 2.6 for many years, but I have often had issues with multiple files. I am trying to do the following.
Use one instance to traverse the root directory.
Use a second instance to open an 'in' file for data input.
Use a third instance to open an 'out' file for data output.
I don't know what filenames will be on the SD card, so I use the first instance to find each 'in' file, ignore any previous 'out' files, and be able to write to new 'out' files one at a time until there are no more files to be read.
The 'in' filename begins with "VEC_".
The 'out' filename begins with "OUT_".
The last 4 characters remain the same.
There doesn't seem to be any problems with 2 instance of fsrw2.6. As soon as the third instance is introduced, strange things happen to unrelated variables in the program (not shown).
Is there something about fsrw2.6 that I need to do to preserve the integrity of memory when more than 2 instances are used?
In this code snippet, characters are read from one file and written to another to simplify the example.
Use one instance to traverse the root directory.
Use a second instance to open an 'in' file for data input.
Use a third instance to open an 'out' file for data output.
I don't know what filenames will be on the SD card, so I use the first instance to find each 'in' file, ignore any previous 'out' files, and be able to write to new 'out' files one at a time until there are no more files to be read.
The 'in' filename begins with "VEC_".
The 'out' filename begins with "OUT_".
The last 4 characters remain the same.
There doesn't seem to be any problems with 2 instance of fsrw2.6. As soon as the third instance is introduced, strange things happen to unrelated variables in the program (not shown).
Is there something about fsrw2.6 that I need to do to preserve the integrity of memory when more than 2 instances are used?
In this code snippet, characters are read from one file and written to another to simplify the example.
CON
dir = 0
in = 1 ' InputFile
out = 2 ' OutputFile
OBJ
sd[3] : "fsrw26"
PRI Main | c
sd[dir].mount(SDCard_DO)
sd[dir].opendir
repeat while NextFile
repeat
c := sd[in].pgetc
if c <> -1
sd[out].pputc(c)
until c == -1
sd[in].pclose
sd[out].pclose
sd[dir].unmount
PRI NextFile | i
repeat ' Ignore filenames starting with "SIM"
i := sd[dir].NextFile(@InputFile) ' Return the next filename in the directory
if i == -1
return false
bytemove(@st,@InputFile,4)
until strcomp(@st,string("VEC_"))==true
i := sd[in].popen(@InputFile,"r") ' Close any open file and open new file
if i == -1
return false
bytemove(@OutputFile+4,@InputFile+4,4)
i := sd[out].popen(@OutputFile,"w") ' Close any open file and open new file
if i == -1
return false
return true
DAT
InputFile byte " .TXT",0
OutputFile byte "OUT_ .TXT",0
st byte " ",0 ' Comparison buffer
Comments
fsrw 2.6 Copyright 2009 Tomas Rokicki and Jonathan Dummer ' ' See end of file for terms of use. ' ' This object provides FAT16/32 file read/write access on a block device. ' Only one file open at a time. Open modes are 'r' (read), 'a' (append), ' 'w' (write), and 'd' (delete). Only the root directory is supported. ' No long filenames are supported. We also support traversing the ' root directory.
Per the above, you can open only one file at a time.
I use SD-MMC_FATEngine to handle up to 3 open files (1 read, 2 write) at a time without issues.
Multiple instances, not multiple files per instance. Good comments in that linked thread, from the authors of fsrw.
About the issue at hand, I feel it is probably not fsrw per se at fault with, "strange things happen to unrelated variables in the program (not shown)."
CON ' Buffering: two sector buffers. These two buffers must be longword ' aligned! To ensure this, make sure they are the first byte variables ' defined in this object. ' byte buf[SECTORSIZE] ' main data buffer DAT buf2 byte 0[SECTORSIZE] ' main metadata buffer
I accidentally deleted an instruction to initialize a variable in a method outside of fsrw26. Multiple file access using multiple instances of fsrw16 as described in the first post works perfectly.
sidecar-racer,
TTA created fsrw26B to enable time and date functions. I don't know who TTA is, and I can't find it in OBEX. Find it embedded in Tracy Allen's reply at https://forums.parallax.com/discussion/164472/fsrw-modified-date-not-working. This is the version I am using.
v2.6A TTA formatting, comments moved under method, some edited. Methods capitalized v2.6B TTA nextfile method captures the create and modified datetimes as longs, methods GetCreated and GetModified return those datetimes as longs. Popen(s, mode) updates the created date location only when file is opened as mode = "w". The "modified" date/time location is updated on either mode="a" or mode="w".
Sidecar-racer, I'm not exactly sure what you mean by, "figure out how to insert time and date". That might refer to the creation and modification date as they exist in the file directory, which is what I implemented in the link dbpage is referring to.
Thank you for all your help to forum members over the years, including myself. In particular, fsrw26B has been great a help to me.
Dennis
In spin, here is how I convert time/date into FAT format:
FATdate := ((s >> 1) | (m << 5) | (h << 11)) | (dd << 16 + (mm << 21) + ((yy+20) << 25)) where: s = seconds m = minutes h = hours dd = day mm = month yy = year