1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//! Minor tools made available for convenience.
use std::ffi::OsStr;
use std::io;
use std::ptr;
use windows_sys::Win32::UI::Shell::ShellExecuteW;
use windows_sys::Win32::UI::WindowsAndMessaging::SW_SHOW;
use crate::convert::ToWide;
/// Open the given directory using the default file manager, which on windows
/// would most likely be Explorer.
///
/// # Examples
///
/// ```
/// use winctx::tools;
///
/// tools::open_dir("D:\\Files")?;
/// # Ok::<_, std::io::Error>(())
/// ```
pub fn open_dir<P>(path: P) -> io::Result<bool>
where
P: AsRef<OsStr>,
{
let path = path.to_wide_null();
let operation = "open".to_wide_null();
let result = unsafe {
ShellExecuteW(
ptr::null_mut(),
operation.as_ptr(),
path.as_ptr(),
ptr::null(),
ptr::null(),
SW_SHOW,
)
};
Ok(result as usize > 32)
}