https://github.com/velopack/filelocksmith-rs
A rust crate to detect running processes locking a file or folder on Windows
https://github.com/velopack/filelocksmith-rs
automatic-updates desktop updater velopack windows
Last synced: 10 days ago
JSON representation
A rust crate to detect running processes locking a file or folder on Windows
- Host: GitHub
- URL: https://github.com/velopack/filelocksmith-rs
- Owner: velopack
- License: mit
- Created: 2024-02-06T21:06:00.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-09-27T19:43:46.000Z (7 months ago)
- Last Synced: 2025-03-27T00:22:29.138Z (27 days ago)
- Topics: automatic-updates, desktop, updater, velopack, windows
- Language: Rust
- Homepage:
- Size: 170 KB
- Stars: 1
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# filelocksmith-rs
[](https://crates.io/crates/filelocksmith)
[](https://github.com/velopack/filelocksmith-rs/blob/master/LICENSE)
[](https://docs.rs/filelocksmith/latest/filelocksmith/)Reliably find and quit processes that are locking a file or folder on Windows.
This is a difficult problem to solve on Windows, as the OS does not provide a built-in or
straight-forward way to do this.Additionally, unlike *nix, files and folders can not be deleted or moved while they are locked by a process.
This library wraps the FileLocksmith module from the Microsoft PowerToys project, which is written in C++.
Further documentation at https://docs.rs/filelocksmith
## Installing
```toml
[dependencies]
filelocksmith = "0.1"
```## Usage
```rust
use filelocksmith::{find_processes_locking_path, quit_processes, pid_to_process_path};let path = "C:\\path\\to\\file.txt";
let pids = find_processes_locking_path(path);// print paths of processes locking the file
for pid in &pids {
println!("[{}] {:?}", pid, pid_to_process_path(*pid));
}// quit the processes locking the file
if quit_processes(pids) {
println!("Processes quit successfully");
}
```