批处理文件来监视增补下载文件夹 [英] batch file to monitor additions to download folder

查看:167
本文介绍了批处理文件来监视增补下载文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要监视补充我的下载文件夹,一个批处理文件,但只新增。事情是这样的:

 :STARTNumOldFiles = GetNumberOfFilesOldDelay_30_SecondsNumNewFiles = GetNumberOfFilesNew如果(NumFilesOld< NumFilesNew)
  run_another_batch_file_I_wrote
  转到START
其他
  转到START

我不想算子文件夹,只需在目录中的文件夹和文件。结果
我一直在寻找这个:结果
目录C:\\文件夹/ B / A |找到/ V / C::结果
但我不知道如何存储这个值,并测试它为<或>。结果
也许有更好的方式来做到这一点,但现在我不能想到一个。也许维护一个列表,如果新的列表中有一个新的文件运行批处理脚本,与新清单取代旧的名单,我真的不知道如何去了解这一点。


解决方案

Anwser 1:

专题<一个下找到href=\"http://www.technologyquestions.com/technology/windows-xp/19003-how-execute-batch-file-automatically-when-file-added-folder.html\"相对=nofollowtitle =如何到时自动在文件夹中添加执行批处理文件>时,文件中的文件夹添加

下面的代码片段应该让你在正确的方向前进,使用 DIR / B 来获取文件和使用的原料名单 FC (文件比较)来检查检查每次执行之间的差异。

您可以使用任务计划一旦推出这个批处理文件每隔x分钟:

 关闭@echo
如果不存在C:\\ OldDir.txt回声。 &GT; C:\\ OldDir.txt
DIR / BD:\\我的文件夹&GT; C:\\ NewDir.txt
等于=无
FC C:\\ OldDir.txt C:\\ NewDir.txt |发现/我没有分歧&GT; NUL&功放;&安培;组
等于= YES
复制/ Y C:\\ Newdir.txt C:\\ OldDir.txt&GT; NUL
如果相等%==%是转到:EOF
REM批处理文件行去这里

Anwser 2:

我一直很喜欢由劳伦斯·里奇的批处理功能的库。其中的一个功能叫做<一个href=\"http://www.commandline.co.uk/lib/treeview/index.php?contents.php&../Batch%20Function%20Library/File%20and%20Directory%20Functions/GetDirStats.html\"相对=nofollow> GetDirStats

GetDirStats 函数返回的文件,子目录和指定目录的总规模数。可能是作为日后参考。虽然它只是在NT4 / 2000 / XP / 2003进行测试。
只要改变紧凑型/秒到契约不扫描子文件夹。

I need a batch file that monitors additions to my Downloads folder, but only new additions. Something like this:

:START  

NumOldFiles = GetNumberOfFilesOld  

Delay_30_Seconds  

NumNewFiles = GetNumberOfFilesNew  

if(NumFilesOld < NumFilesNew)  
  run_another_batch_file_I_wrote
  goto START
else
  goto START

I do not want to count subfolders, just the folders and files in the directory.
I have been looking at this:
dir "C:\folder" /b/a |find /v /c "::"
but I don't know how to store this value and test it as < or >.
Maybe there is a better way to do this, but I can't think of one right now. Maybe maintain a list and if the new list has a new file run the batch script, replace the old list with the new list, I'm not really sure how to go about this.

解决方案

Anwser 1:

Found under the topic how to execute batch file automatically when file is added in folder

The following snippet should get you going in the right direction, uses dir /b to get a raw list of files and uses fc (file compare) to check for differences between each execution of the check.

You could use the Task Scheduler to launch this batch file once every x minutes:

@echo off
if not exist c:\OldDir.txt echo. > c:\OldDir.txt
dir /b "d:\My Folder" > c:\NewDir.txt
set equal=no
fc c:\OldDir.txt c:\NewDir.txt | find /i "no differences" > nul && set
equal=yes
copy /y c:\Newdir.txt c:\OldDir.txt > nul
if %equal%==yes goto :eof
rem Your batch file lines go here

Anwser 2:

I have always liked a library of batch functions by Ritchie Lawrence. One of those functions is called GetDirStats.

The GetDirStats function returns the number of files, subdirectories and total size of a specified directory. Might be handy for future reference. Although it's only tested on NT4/2000/XP/2003. Just change "compact/s" to "compact" to not scan subfolders.

这篇关于批处理文件来监视增补下载文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆