user823447
user823447

Reputation: 146

How to Detect File Rename / Move in Windows

I'm trying to detect when a file is being moved or renamed in windows and I want to then use that change to update a database.

When I say file move: I mean moving from one directory to another from ".../A/foo.txt" to ".../B/foo.txt". When I say file rename: I mean renaming but staying in the same directory ".../A/foo.txt" to ".../A/bar.txt"

I know that linux and most people treat them as the same thing, and for my purposes they are the same thing. I just want to know the actual file path after and be able to match it to the original file path even in circumstances where there is a batch move.

I am using python for the parent program, but I am willing to use any coding language though it preferably is Java/Python/some form of C.

Upvotes: 3

Views: 1867

Answers (3)

marc3l
marc3l

Reputation: 2605

If you use java 7, you can simply use WatchService and WatchKey. This is a observer to watch a directory and each time something is changed, created or deleted you can do an action/file handling.

Upvotes: 3

Akintayo Olusegun
Akintayo Olusegun

Reputation: 917

In Java (WatchService and WatchKey) - http://docs.oracle.com/javase/tutorial/essential/io/notification.html

In Python (Watchdog) - https://pypi.python.org/pypi/watchdog

Upvotes: 0

bwbrowning
bwbrowning

Reputation: 6530

I recommend using the watchdog python module https://github.com/gorakhargosh/watchdog

It can handle these situations as well as other filesystem events

Upvotes: 0

Related Questions