简体   繁体   English

在Win 7的特定文件夹中创建新文件时执行批处理文件

[英]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. 原始问题:我正在php网站上工作,其功能之一是从用户上载的Word文件中读取数据,然后将条目插入到某些数据库中。 Note: the server is running windows (devil windows!). 注意:服务器正在运行Windows(魔鬼窗口!)。

My Solution: Write a java program to do the word file reading and database inserting stuff, using java Apache POI library. 我的解决方案:使用Java Apache POI库编写一个Java程序来进行Word文件读取和数据库插入操作。 Then execute the java program in one bat file. 然后在一个bat文件中执行Java程序。 Then new problem occurs... 然后出现新问题...

New Problem: How can we make a specific bat file run on a specific file system event? 新问题:如何使特定的bat文件在特定的文件系统事件上运行? 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. 如果您是我,我将在运行您拥有的Java应用程序的服务器上实施某种计划的任务http://technet.microsoft.com/zh-cn/library/cc772785%28WS.10%29.aspx )用于添加文件。 Depending on your traffic, you could set it to run every 5 minutes, or every 5 hours, or whatever. 根据您的流量,您可以将其设置为每5分钟,每5小时或任何时间运行。

That Java app would then do this: 然后,该Java应用程序将执行以下操作:

  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. 同时,我很惊讶您没有通过Web应用程序用PHP实现某些功能。 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? 如果您的网站已经在php中,那么将此应用程序逻辑也保留为PHP的一部分,这是否有意义? To each their own. 给每个人自己。

If you went the php route , a super simple approach would be this: 如果您使用php路线 ,则超级简单的方法是:

  • have some page submit_doc.php with a form where users can upload a doc 有一些页面带有表单的submit_doc.php ,用户可以在其中上传文档

  • when they hit the submit button, some other php file would execute, say upload_doc.php 当他们点击“提交”按钮时,将执行其他一些php文件,例如upload_doc.php

  • upload_doc.php would handle connecting to the db and adding the file to the db upload_doc.php将处理连接到数据库并将文件添加到数据库的操作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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