简体   繁体   中英

execute a batch file when a new file is created in specific folder on win 7

Let me first describe where I am. For readability, that will take three paragraphs.

Original Problem: I am working on a php website, one function of which is to read data from a Word file users upload and then insert the entry into some database. Note: the server is running windows (devil windows!).

My Solution: Write a java program to do the word file reading and database inserting stuff, using java Apache POI library. Then execute the java program in one bat file. Then new problem occurs...

New Problem: How can we make a specific bat file run on a specific file system event? In my case, the event will be file creation in one assigned folder.

Wish I have made myself totally understood. Waiting for your help. Any suggestion is appreciated.

If I were you, I would implement some kind of scheduled task ( http://technet.microsoft.com/en-us/library/cc772785%28WS.10%29.aspx ) on the server that runs the Java app you have for adding the files. Depending on your traffic, you could set it to run every 5 minutes, or every 5 hours, or whatever.

That Java app would then do this:

  1. Look at that directory

  2. If it sees some file(s), loads the file(s) into the database

  3. When it is finished loading the files, it would delete them from the directory (so it doesn't add them the next time the task executes).

At the same time, I'm surprised you're not implementing something with PHP through the web app. If your website is already in php, wouldn't it make sense to keep this application logic as part of the PHP stuff as well? To each their own.

If you went the php route , a super simple approach would be this:

  • have some page submit_doc.php with a form where users can upload a doc

  • when they hit the submit button, some other php file would execute, say upload_doc.php

  • upload_doc.php would handle connecting to the db and adding the file to the db

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM