Reputation: 67
How do I create a file in a certain folder in Rust?
I have tried the following approaches:
let f = File::create(Path::new(format!("{}{}","/files/",filename).as_str()));
let f = File::create(format!("{}{}","/files/",filename));
Both result in:
The system cannot find the path specified. (os error 3)
I have managed to create the file in the same directory as the executable with:
let f = File::create(format!("{}",filename));
So how do I go about creating files in a specific directory?
ls
on basefolder:
PS C:\trust\svd2rust\target\debug> ls
Directory: C:\trust\svd2rust\target\debug
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2017-01-24 12:13 .fingerprint
d----- 2017-01-24 12:13 build
d----- 2017-01-26 10:06 deps
d----- 2017-01-24 12:13 examples
d----- 2017-01-26 07:18 files
d----- 2017-01-24 12:13 incremental
d----- 2017-01-24 12:13 native
-a---- 2017-01-24 12:13 0 .cargo-lock
-a---- 2017-01-26 10:06 1079240 libsvd2rust.rlib
-a---- 2017-01-24 21:08 27608 log.rs
-a---- 2017-01-24 13:55 27372 log2.rs
-a---- 2016-08-23 15:07 565888 STM32F401x.svd
-a---- 2016-08-23 15:07 912360 STM32F401xE.svd
-a---- 2016-08-23 15:07 1907985 STM32F40x.svd
-a---- 2017-01-26 10:06 11761561 svd2rust.exe
Upvotes: 1
Views: 398
Reputation: 67
Using "files/" instead of "/files/" solved the problem.
It seems "/files/" references to the absolute path of C:\files, while "files/" references to the relative path of the executable.
So when using "/files/" it did't work since there was no folder C:\Files.
Upvotes: 2