1

Each time I change a file, I need to go and manually copy it to another folder, so that the updated version would exist there. I know about mklink, but that's not feasible in my case.

Is there a way to hook a bat file to save event of a file in Windows? Because if that's possible, I can create a bat file to copy the file automatically. If not, what other options I might have, excluding mklink.

4
  • 2
    It sounds like what you actually want is some file sychronisation software. en.wikipedia.org/wiki/…
    – Mokubai
    Jul 14, 2015 at 6:31
  • 1
    why not just put the bat file to scheduled task and run it every minutes? there're ways to monitor file change but requires additional software running on background, the low-tech scheduled task seems to fit nicely here.
    – lex
    Jul 14, 2015 at 6:38
  • use xcopy or robocopy and just let the bat run repeatedly. superuser.com/questions/308277/…
    – lex
    Jul 14, 2015 at 6:40
  • @Chris.C, I need it on-demand. That way, I should wait 1 minutes each time I change the file, or otherwise, I should find a way to copy the file each 5 seconds, which makes resource usage a nightmare (possibly). Jul 14, 2015 at 6:58

2 Answers 2

1

You can do this in powershell.

First of all go and grab FileSystemWatcher from here : https://gallery.technet.microsoft.com/scriptcenter/Powershell-FileSystemWatche-dfd7084b

You don't need all of that - I've trimmed it down to this, which should work for you:

$destination = "\\Location\file\should\go" 
$folder = 'c:\scripts\test' # Enter the root path you want to monitor. 
$filter = '*.*'  # Enter filename here. 
$fsw = New-Object IO.FileSystemWatcher $folder, $filter -Property @{IncludeSubdirectories = $false;NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'} 
Register-ObjectEvent $fsw Changed -SourceIdentifier FileChanged -Action  
{ 
$name = $Event.SourceEventArgs.Name 
Copy-Item $name $destination -force
} 

This should only trigger when it detects a change on the file.

I've not tested this but it should be close enough to get you going.

You'd need to run this bit of powershell each time you start the machine, a start up item or scheduled task to launch it would do.

0

I would recommend using FreeFileSync to keep that file synchronized. FreeFileSync has a side tool called RealtimeSync that triggers a synchronization task each time it detects a change in a given folder. You only have to create a synchronization task for that file and then run RealtimeSync with that task and it will be 'automagically' copied each time is modified.

For a complete tutorial see How to Synchronize Files and Folders Using FreeFileSync in Windows

Important footnote: though FreeFileSync is Open Source and is licensed under the GPL, it comes bundled with OpenCandy PUP/PUA, so either install it with the network connection disabled or make sure you uncheck the crapware installation offer. Also, you can just unpack the installer using 7zip or PeaZip and just run it without installation.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .