Skip to main content

show

Function show 

Source
pub fn show(path: impl AsRef<Path>) -> Result<()>
Expand description

Shows a hidden file or directory.

§Platform-specific behavior

  • On Unix, this function renames the file to start with a character other than ..
  • On Windows, this function clears the hidden file attribute to the file.

§Errors

§On Unix

Returns Err if any of the following are true:

  • path terminates in ...
  • path is not valid UTF-8.
  • The file name does not start with ..
  • std::fs::rename returns an error.

§On Windows

Returns Err if any of the following are true:

§Examples

§On Unix

let temp_dir = tempfile::tempdir().unwrap();
let temp_dir = temp_dir.path();
let hidden_file_path = temp_dir.join(".foo.txt");
let file_path = hf::unix::normal_file_name(&hidden_file_path).unwrap();
assert_eq!(file_path, temp_dir.join("foo.txt"));
assert!(!hidden_file_path.exists());
assert!(!file_path.exists());

File::create(&hidden_file_path).unwrap();
assert!(hidden_file_path.exists());
assert!(!file_path.exists());

hf::show(&hidden_file_path).unwrap();
assert!(!hidden_file_path.exists());
assert!(file_path.exists());

assert!(hf::show("bar.txt").is_err());
assert!(hf::show(".bar.txt/..").is_err());
assert!(hf::show(".bar.txt").is_err());

§On Windows

let temp_dir = tempfile::tempdir().unwrap();
let file_path = temp_dir.path().join("foo.txt");
assert!(!file_path.exists());

File::create(&file_path).unwrap();
assert!(file_path.exists());
assert!(!hf::is_hidden(&file_path).unwrap());

// Set the hidden file attribute.
Command::new("attrib")
    .arg("+h")
    .arg(&file_path)
    .status()
    .unwrap();
assert!(hf::is_hidden(&file_path).unwrap());

hf::show(&file_path).unwrap();
assert!(file_path.exists());
assert!(!hf::is_hidden(file_path).unwrap());

assert!(hf::show("bar.txt").is_err());