Directory issue

This is a little code:

const file_path::String = "./try"
file_out = open(file_path, "w")
a::Int64 = 1
write(file_out, a)
close(file_out)

file_in = open(file_path, "r")
b::Int64 = read(file_in, Int64)
close(file_in)
println(b)

info = isdir(file_path)
println(info)
mkdir(file_path)

It creates and reads a binary file try (is it faster than saving it as txt?)
The i wonder if I can create a folder, a directory, called try.
A consistency check.
isdir says there is no directory with this name and it’s right.
However mkdir throws an error

isdir(file_path) returns false because file_path is not an existing directory – it is an existing file. You can use isfile(file_path) to test if file_path is an existing file, or ispath(file_path) to test if file_path exists at all (be it a file or a directory).

If there is a file called Data, can’t I create a directory called Data too, or would they overlap for the system?

If I want to create a file and write data in binary to be fast, can I save the file as Data.txt instead?

This way there will be no overlap

Files and directories are referenced by their paths. If it were allowed to have a directory and a file at the same path, that path would not be unique and hence would be useless as a reference. So yes, if there is a file called Data, you cannot create a directory called Data (in the same directory).

A file’s suffix does not decide if the file’s content is binary or text. As long as you use the write function, the file will contain binary representation. For text representation, there is print.

1 Like