Re: Contrary read_file()
- Posted by ChrisB (moderator) Jan 16, 2019
- 965 views
Sometimes writing English pseudocode helps
alrobnett said...
insert_nmbr = prompt_number("Which subtree?:", {1, number_of_files}) insert_path = splice("/home/allen/Extracted/", extracted_files[insert_nmbr][D_NAME], 23) if file_exists(insert_path) then --if the file exists then insert_fn = open(insert_path, "wb") --open it for writing in binary (ie delete it and write a new one) else --otherwise if the file doesn't exist abort(insert_fn) --abort the program, and display the file handle --ah, if I didn't open the file for writing, --then where has that handle come from end if if insert_fn < 1 then --if the file doesn't exist then --(but note I would never have got here if the file didn't exist) puts(1, "could not open insert file") --print your error reporting and stuff crash_file("Could open insert file") --looks like this block would never be run abort(0) end if insert_tree = read_file(insert_fn, BINARY_MODE) --looks like it's empty because you deleted it
gives no hint of an error. The resulting file path is /home/allen/Extracted/(name of selected file). insert_fn is 4. But insert_tree is an empty sequence, {}. The actual file is a megabyte long.
Cheers
Chris