Skip to content

A rust crate to detect running processes locking a file or folder on Windows

License

Notifications You must be signed in to change notification settings

maiji1990/filelocksmith-rs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

filelocksmith-rs

Version License Documentation

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

[dependencies]
filelocksmith = "0.1"

Usage

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");
}

About

A rust crate to detect running processes locking a file or folder on Windows

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 56.1%
  • C++ 43.9%