A function to copy a file from one location/name to another.
See function for explanation. Neither the function nor the test program checks to confirm the copy. Be careful not to select an existing file, or it will be overwritten immediately!
filedialog "Open file to copy...", "*.*", toCopy$
if(toCopy$ ="")thengoto[exit]else
filedialog "Save file as...", "*.*", copyTo$
if(copyTo$ ="")thengoto[exit]else
fileCopied = CopyFile(toCopy$, copyTo$)
n$ = word$("not .", abs(not(fileCopied)), ".")
notice "File "; n$; "copied."endifendif[exit]endfunction CopyFile(fileToCopy$, copyToFile$)'If source and destination are not blank...if(not(fileToCopy$ ="")andnot(copyToFile$ =""))then'Open both files.
open fileToCopy$ for input as #fileToCopy
open copyToFile$ for output as #copyToFile
'Get size of source file.
ftcLen =lof(#fileToCopy)'Set the maximum chunk size to be the smaller'of the source file size or 4096. Modify the'value to adjust the speed of the function'for very large files.
CHUNK.SIZE= min(ftcLen, 4096)whilenot(eof(#fileToCopy))'Smaller of max size or bytes still unread.
chunk = min(ftcLen, CHUNK.SIZE)'Read certain amount of file into a buffer.
buffer$ =input$(#fileToCopy, chunk)'Decrement remaining byte count by how much'was read.
ftcLen = ftcLen - chunk
#copyToFile buffer$;
wend
close #fileToCopy
close #copyToFile
CopyFile =1endifendfunction
CopyFile() Function
A function to copy a file from one location/name to another.