#Create file in tmp directory
48 messages · Page 1 of 1 (latest)
the first one can return an error, what is it?
you can see it with std::fs::write("/tmp/iqbal.txt", "iqbal").unwrap(); for a quick and dirty method
it does not return an error, but when I want to access it, it is not there
its like it is not creating that file
?eval ```rs
let name = "/tmp/iqbal.txt";
std::fs::write(name, "iqbal").unwrap();
std::fs::read_to_string(name)
Running `target/debug/playground`
Ok("iqbal")
there must be something else going on
supposedly this code can overwrite the content inisde it correct?
?eval ```rs
let name = "/tmp/iqbal.txt";
std::fs::write(name, "iqbal").unwrap();
let first = std::fs::read_to_string(name);
std::fs::write(name, "abcdef").unwrap();
let second = std::fs::read_to_string(name);
(first, second)
Running `target/debug/playground`
(Ok("iqbal"), Ok("abcdef"))
yes
if lets say it did not overwrite, do u know what is the cause? thank you for helping btw
I'm leaning towards that this is a problem with your diagnosis
although it's possible for the file content to not have been flushed to the actual file system
it should eventually be there though
something else could be writing to the file too
let me try tell you want I actually want to do
I want to create a file at dir /tmp, after that I overwrite the content of the file
?crate tempdir
A library for managing a temporary directory and deleting all contents when it's
dropped.
0.3.7
12 557 139
this is one crate that's useful for this use case
but you still have to write the files yourself
what you've shown didn't have anything indicating that it wouldn't work
although now that I see it, you tried to make a directory called *.txt
maybe that was confusing?
if you make a directory with a name, you can't make a file with the same name
?eval ```rs
let name = "/tmp/iqbal.txt";
std::fs::create_dir_all(name).expect("should create dir");
std::fs::write(name, "iqbal").expect("should write to file");
std::fs::read_to_string(name)
Running `target/debug/playground`
thread 'main' panicked at 'should write to file: Os { code: 21, kind: IsADirectory, message: "Is a directory" }', src/main.rs:4:31
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
let me try, thank you
thread 'main' panicked at 'should write to file: Os { code: 31, kind: Uncategorized, message: "Is a directory" }' what does this mean?
it's a Debug representation of the error
it means this one is created by someone? and I need to ask the person who create this error message?
what?
sorry, I don't understand this
the error message itself tells you that there's already a directory with that name
so you can't write to it
you can only write to files
do you understand what all the code snippets I showed do?
i think I do, it first create a directiry, then it write to that file, and then read from that file correct?
the last snippet yes
i see
thread 'main' panicked at 'should write to file: Os { code: 28, kind: InvalidInput, message: "Invalid argument" }',
do you know what this means
that might be that you gave it a path with invalid characters
or it could be something else
?eval ```rs
let name = "/tmp/@#$&_-()=%*':!?+%@'?.txt";
std::fs::write(name, "iqbal").unwrap();
std::fs::read_to_string(name)
Running `target/debug/playground`
Ok("iqbal")
lol ok I can't find an invalid character