Monitor a folder for file changes. If changed then run bat
Moderator: DosItHelp
Monitor a folder for file changes. If changed then run bat
Hey everyone,
Id like to monitor a folder and all of it's sub folders. If a file is added or modified within this folder structure then run another bat file I already have written.
Example:
Monitor c:\art_assets
if anything changes within this folder or any of it's sub folders then run "build_assets.bat"
Id really appreciate the help You guys are the best and have already saved me a ton of time in the past.
Id like to monitor a folder and all of it's sub folders. If a file is added or modified within this folder structure then run another bat file I already have written.
Example:
Monitor c:\art_assets
if anything changes within this folder or any of it's sub folders then run "build_assets.bat"
Id really appreciate the help You guys are the best and have already saved me a ton of time in the past.
Re: Monitor a folder for file changes. If changed then run
Perfect application for this is called Watch Directory. License is cheap and it works great.
Re: Monitor a folder for file changes. If changed then run
Thanks for the tip Squashman. Ive spoken to my management about this application but was told not to concern myself with such matters. So whatever I go with has to be made by myself Ill definitly look into this app though for home / personal use! Hopefully a bat file isnt too difficult for this task. I have no idea if what I am asking is a huge undertaking or not unfortunately
Re: Monitor a folder for file changes. If changed then run
It is your concern because you are the one who has to implement this task. I pretty much work for the largest printing company in the world and we have dozens upon dozens of licenses for Watch Directory. They use it here in the states and our facilities in Europe as well. It has so much bang for the buck it is not even funny.
I would not be able to automate 600+ tasks daily without it.
I would not be able to automate 600+ tasks daily without it.
Re: Monitor a folder for file changes. If changed then run
Here is an option for you.
Create a text file with the contents of the TREE of folders and files.
The text file will contain the full path to the file, the date modified and the file size.
This can easily be done with the DIR command executed within the FOR command.
You would run the above code once you know everything is up to date and you have already run your build command. This code would only be run once. This will give you a base listing of what is currently in your folder and sub folders to compare to another file that will be created.
Now every X minutes you could schedule this batch file to run to compare the previous tree structure to the current tree structure.
Put all your Batch files that you will be running into a folder outside of your folder tree that you are monitoring. This is where the Tree listings will exist as well.
Create a text file with the contents of the TREE of folders and files.
The text file will contain the full path to the file, the date modified and the file size.
This can easily be done with the DIR command executed within the FOR command.
Code: Select all
@echo off
pushd "c:\art_assets"
FOR /F "delims=" %%G IN ('DIR /B /S') DO >>"C:\path to BatchFiles\TreeExisting.txt" ECHO %%~G,%%~tG,%%~zG
popd
You would run the above code once you know everything is up to date and you have already run your build command. This code would only be run once. This will give you a base listing of what is currently in your folder and sub folders to compare to another file that will be created.
Now every X minutes you could schedule this batch file to run to compare the previous tree structure to the current tree structure.
Code: Select all
@echo off
pushd "c:\art_assets"
FOR /F "delims=" %%G IN ('DIR /B /S') DO >>"C:\path to BatchFiles\TreeCurrent.txt ECHO %%~G,%%~tG,%%~zG
popd
FC TreeExisting.txt TreeCurrent.txt >nul
IF %ERRORLEVEL% GTR 0 THEN (
CALL build_assets.bat
del TreeExisting.txt
ren TreeCurrent.txt TreeExisting.txt
)
Put all your Batch files that you will be running into a folder outside of your folder tree that you are monitoring. This is where the Tree listings will exist as well.
Re: Monitor a folder for file changes. If changed then run
If you are familar with c++ this may help you:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365261(v=vs.85).aspx
penpen
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365261(v=vs.85).aspx
penpen
Re: Monitor a folder for file changes. If changed then run
Some PowerShell and Vbscript options here as well.
http://superuser.com/questions/226828/h ... is-created
http://superuser.com/questions/226828/h ... is-created
Re: Monitor a folder for file changes. If changed then run
This is the type of methodology I was thinking of. Or just write the whole dir /s to a file and then run it again after x mins and compare the files. If they don't compare perfect, something has changed.Squashman wrote:Here is an option for you.
Create a text file with the contents of the TREE of folders and files.
The text file will contain the full path to the file, the date modified and the file size.
This can easily be done with the DIR command executed within the FOR command.Code: Select all
@echo off
pushd "c:\art_assets"
FOR /F "delims=" %%G IN ('DIR /B /S') DO >>"C:\path to BatchFiles\TreeExisting.txt" ECHO %%~G,%%~tG,%%~zG
popd
You would run the above code once you know everything is up to date and you have already run your build command. This code would only be run once. This will give you a base listing of what is currently in your folder and sub folders to compare to another file that will be created.
Now every X minutes you could schedule this batch file to run to compare the previous tree structure to the current tree structure.Code: Select all
@echo off
pushd "c:\art_assets"
FOR /F "delims=" %%G IN ('DIR /B /S') DO >>"C:\path to BatchFiles\TreeCurrent.txt ECHO %%~G,%%~tG,%%~zG
popd
FC TreeExisting.txt TreeCurrent.txt >nul
IF %ERRORLEVEL% GTR 0 THEN (
CALL build_assets.bat
del TreeExisting.txt
ren TreeCurrent.txt TreeExisting.txt
)
Put all your Batch files that you will be running into a folder outside of your folder tree that you are monitoring. This is where the Tree listings will exist as well.
Re: Monitor a folder for file changes. If changed then run
Samir wrote:This is the type of methodology I was thinking of. Or just write the whole dir /s to a file and then run it again after x mins and compare the files. If they don't compare perfect, something has changed.
That is basically what I said I was doing.
Re: Monitor a folder for file changes. If changed then run
Agh, I missed the FC somehow. I only skimmed your code.Squashman wrote:Samir wrote:This is the type of methodology I was thinking of. Or just write the whole dir /s to a file and then run it again after x mins and compare the files. If they don't compare perfect, something has changed.
That is basically what I said I was doing.
Re: Monitor a folder for file changes. If changed then run
I have had success in doing just this kind of monitoring using a open freeware software package that i got from
https://sourceforge.net/projects/freefilesync/?source=directory
This web page has an extensive list of features.
FreeFileSync has two components. One does various kinds of backups(which I did not use) and is triggered by the activity monitoring component RealtimeSync which presents a menu window to specify
This command line is just the name of my previously written batch file with parameters as would appear on a call statement. I set a monitor idle time of a few minutes from first activity to trigger the backup to external media.
This has triggered flawlessly since I installed it into the startup folder last year.
John
https://sourceforge.net/projects/freefilesync/?source=directory
This web page has an extensive list of features.
FreeFileSync has two components. One does various kinds of backups(which I did not use) and is triggered by the activity monitoring component RealtimeSync which presents a menu window to specify
- The folders to watch
- A command line
This command line is just the name of my previously written batch file with parameters as would appear on a call statement. I set a monitor idle time of a few minutes from first activity to trigger the backup to external media.
This has triggered flawlessly since I installed it into the startup folder last year.
John