在使用tar进行压缩的时候如何使用绝对地址作为输入和输出地址?
运行完毕直接就报错是 在设置路径时,档案中的路径必须相对, 但我想要使用绝对路径. 希望大佬们不吝解答
运行结果
C:/Users/BORBER/.cargo/bin/cargo.exe run --color=always --package rust_test --bin rust_test
Finished dev [unoptimized + debuginfo] target(s) in 0.03s
Running `target\debug\rust_test.exe`
Error: Custom { kind: Other, error: "paths in archives must be relative when setting path for " }
error: process didn't exit successfully: `target\debug\rust_test.exe` (exit code: 1)
main.rs
use std::fs::File;
use flate2::Compression;
use flate2::write::GzEncoder;
fn main() -> Result<(), std::io::Error> {
// Create Gzip file
let compressed_file = File::create("backup.tar.gz")?;
let mut encoder = GzEncoder::new(compressed_file, Compression::default());
{
// Create tar archive and compress files
let mut archive = tar::Builder::new(&mut encoder);
archive.append_dir_all("C:\\Users\\BORBER\\game", "C:\\Users\\BORBER\\game\\Baldurs.Gate.Enhanced.Edition.v2.6.6.0.Multi.15")?;
}
// Finish Gzip file
encoder.finish()?;
Ok(())
}
cargo.toml
[package]
name = "rust_test"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tar = "0.4"
flate2 = { version = "1.0.17", features = ["zlib-ng-compat"], default-features = false }
推荐文章: