Attached is my attempt to use File API to read and write binary files. Like the VB6 FreeFile command, it uses GetFNum to find the first available file structure defined as an array of:
The size of the array is defined by MaxFiles, and the FileName is stored as a long pointer to an associated string array containing the actual file names. This was done to maximize speed by maintaining fixed length User Defined Types. For the same reason, fixed length buffers were also used along with the length to prevent memory having to be reassigned with changes in length. Instead of accessing file data by number, file handles are used instead. Clearing the FileHndl enables the UDT to be reused without having to clear the 2 other variables.
In this demo, the file write routine is simply used to demonstrate its use. It doesn't actually store any data, but like the command line copy, it recognizes that if a file by the chosen name already exists, it prompts you to overwrite it. Choosing to overwrite it truncates the file size before writing. The copy routine utilizes both read and write.
In this demo, the default write directory is the current operating directory. A short demo file (kitty.htm) is also included.
J.A. Coutts
Code:
Private Type FileStruct
FileName As Long
FileHndl As Long
FileLen As Long
End Type
In this demo, the file write routine is simply used to demonstrate its use. It doesn't actually store any data, but like the command line copy, it recognizes that if a file by the chosen name already exists, it prompts you to overwrite it. Choosing to overwrite it truncates the file size before writing. The copy routine utilizes both read and write.
In this demo, the default write directory is the current operating directory. A short demo file (kitty.htm) is also included.
J.A. Coutts