Schedule Task to start based on a file - windows-server-2008

I have a folder in my Windows 2008 Server.
I have a Windows Scheduled Task that runs every 15 minutes that will read the files from the above mentioned folder and store it in the database. Once stored, the file will be moved to a different folder.
Is there any way that we can schedule the task so that it kicks off the moment it sees a new file in the folder instead of waiting for 15 minutes or run even if there are no files in the folder?
Please help.
Thanks

If you are willing to write a program in .NET I think you can use the FileSystemWatcher class to do this.
http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx
I believe this can be used from PowerShell as well, never done that though!

Related

Check for new files at program start

I need to write a .dll for a program that works with some files.
I need to code that every time someone starts the program, it should check in a folder for new files and if there are new ones, it should copy them automatically in the programs folder and restart the program. If there are none the program should just start normally.
My problem is that I dont know how to make the program identify new files since the last time the program was started/closed, because I dont want to monitor the folder the whole time the program is running, but only at the start of the program.
I thought about comparing the files in the 2 folders, but with houndreds of files it would be bad perfomance wise, wouldnt it ?
Besides that if someone knows how to automatically copy files and could give me an idea for it too, that would be great.
Iam very new to vb.net and only have limited experience with coding, so forgive me if I ask some easy questions.
Every idea and answer is much appreciated. Thank you!
UPDATE: Thank you very much guys for your ideas, gonna test some of these :)
You could try this approach.
I use this approach in backing-up my files into our server.
This will check for new files and newer-dated version of an existing file (if any) then overwrites it.
I used the XCopy command in my batch file
Creating batch files is pretty much basic.
Open a Notepad
Paste this command: XCopy "C:\YourSourceFolder\*.*"
"D:\YourDestinationFolder" /D /S /Y
Save the file having an extension of .bat
Explanation regarding XCopy:
*.* specifies that all the files inside your directory will be
copied.
/D means it copies only those files whose source time is newer
than the destination time.
/S will copy directories and sub directories except empty ones.
/Y overwrites existing files without prompting
Source: MS-DOS XCopy Command
Now, running it through VB.Net takes only a one line of code. You could put it in a Button_Click,Timer_tick or any events you prefer.
System.Diagnostics.Process.Start("C:\YourBatFile.bat")
Of course, the directory still varies on where did you saved your .bat file.
Source: Run a batch file in VB.Net
In your case: You could use a timer that executes this batch file in an interval of your preference.
You can create a windows service and use a filewatcher https://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher(v=vs.110).aspx

How to overwrite Files for Update Procedure

I'm trying to create an updater for my app in VB.NET, No, I do not want to use clickonce, it sucks because I have to deal with managing self signed certs etc.
I know the code to check for new update files:
http://pastebin.com/ZjYBWABu
I also know the code for specifying where those files download to, the issue is I dont want to just download 1 .exe...I want to download all the latest build files which I would have uploaded to my server, which i would have taken from my Bin\release folder of my project.
Then when the updater downloads the files to a directory, it would go to the directory of the application, and somehow overwrite/replace all the files that have changed...maybe by using a hash or something?
I do not know how to proceed with this. What I do know is this.
The updater and the main app would have to be separate so that the updater could do the replacing while the app is closed so it doesn't get file in use errors. After the updater app has finished it would then start up the main app from the new exe.
Would appreciate help here thank you guys.
I am currently working on a project for which I have to implement a similar approach for updates. The project is lengthy, it would take some time to finish. But this is how I have planned to apply the updates:
There will be two main parts of the application Launcher (main application program) and Updater (To download files from server and replace them with the new ones and then launch the new file)
The application will have the option to manually check for update and also to check for update on startup.
If an update is available, it asks the user to apply the update now or later.
If the user selects to apply the update now then Updater application is executed in a separate process and then Launcher application is closed from within the code in Launcher. I have following approaches in my mind to launch another program from within first one and then exit:
Execute the Updater directly from within the Launcher using Process.Start
If that causes problem then as second approach launch command prompt from Process.Start, execute another program (Updater) from command prompt, close the command prompt and then exit the Launcher.
The Updater application then downloads all the relevant files from the server and upon completion old application files are replaced with the new ones.
Update availability information from server will include the new Version_No of application. For the purpose of providing all files for update, I will compress (zip) all of them in a single file named as Application.Version_No (as given by the server).
Upon download completion decompress (unzip) them to a folder named as the same Application.Version_No.
After decompressing all the files in this (Application.Version_No) folder will be copied to the Bin folder of application.
The new application Launcher file is executed in a separate process and Updater application is closed from within the code in Updater.
I have NOT yet tried this scenario as currently my focus is on completing the main application, but surely this must work.
UPDATE:
Another approach to check for updates is to use a bootstrap like application startup. It will be the main entry point of the program. Upon execution it will check for the updates and if there is none the Launcher is executed otherwise it will download the files, replace the old ones and then execute the new / updated Launcher.
For copying / overriding the files
One approach is to include only those files in the compressed (zip) file which are required to be replaced with the old ones and then after the download completes, either directly decompress them to the Bin folder or decompress them to a designated folder and then copy all of them to the Bin folder.
As another approach which seems somewhat lengthy, an additional helper file (XML, text or any other format) could be prepared for the download.
This helper file contains information of updated files like version number of each file, location where these are to be copied etc.
The files may be downloaded to a specific folder named as the new application version.
After downloading all the required files to a specific folder process each file mentioned in the helper file. Compare version of every old file with the new downloaded file. If it is latest then replace it in the folder mentioned in the helper file.
As another step in between all the downloads may be verified prior to copying and replacing.
Built an updater that ships with a daemon. Main project here:
https://github.com/UVLabs/dotNetUpdatify
There should be a way to eliminate the use of the daemon, if i figure it out i will update.

Intelli j - running a task after a file save

Im using Intellij IDEA 13 and I'd love to have a sh script file to be executed as soon as I save a file. Any ideashow to do this ? I can't seem to find anything.
This might not be a good idea, because your files are saved very often, and this script could have a performance impact on your machine. Perhaps it is enough to run the script automatically before a check-in into a VCS?
Anyway, if you insist, you could use external tools in order to monitor the file system for changes,
On Windows see https://www.raymond.cc/blog/3-portable-tools-monitor-files-folders-changes/
On Linux see https://superuser.com/questions/363511/execute-script-program-when-file-changes

Launching a JAR file using Apache as a background process

I have a data parsing utility in the form of a runnable JAR file. I also have an Apache server (Ubuntu 12.04) to which data files are uploaded. Is there anyway that I could launch said JAR file as a background process when a file is uploaded? (FYI: File access by multiple processes isn't a concern here; I've got file locking in place.)
Related idea: if the above isn't possible, I could always launch the aforementioned JAR file from a bash script. However, I'm still not sure how to do that via Apache. I'm quite a novice at using it effectively.
Edit: Just noticed this potential php solution. Apache folks: is this a good idea, or is there a better solution?
Maybe you can use File Alternation Monitor to achieve this. It can be configured as a background daemon which performs operations if the new file is spotted. If you want to avoid starting while the file is currently uploaded, wait approx. 5 minutes after the file change time and start processing your utility.
I use a similar technique for monitoring uploaded files on a Samba share and it works flawless.

FTP only changed files in MSBuild

An MSBuild project copies its output to a directory on a server. Each day, only a few files change and most have an older creation date.
I can FTP this to a remote server with MSBuild tasks. But how can I do this FTP and only copy the few files that have changed?
To do this you'll need something that will manage the sync for you - that is that will keep track of what file is where and update accordingly.
We have used FTPSync to do the file sync bit very tidly for a number of sites.
From MSBuild you can call an external program - so putting the two together will probably work providing your are consistently synching from the same location (otherwise its going to be more interesting!)