批处理文件以监视添加到下载文件夹 [英] batch file to monitor additions to download folder

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

问题描述

我需要一个批处理文件来监控我的下载"文件夹中的添加内容,但只需要添加新内容.像这样:

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

我不想计算子文件夹,只计算目录中的文件夹和文件.
我一直在看这个:
dir "C:folder"/b/a |find/v/c "::"
但我不知道如何存储这个值并将其测试为 <或 >.
也许有更好的方法来做到这一点,但我现在想不出一个.也许维护一个列表,如果新列表有一个新文件,则运行批处理脚本,用新列表替换旧列表,我不确定该怎么做.

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.

推荐答案

答案 1:

以下代码段应该能让您朝着正确的方向前进.它使用 dir/b 来获取文件的原始列表,并使用 fc(文件比较)来检查每次执行检查之间的差异.

Answer 1:

The following snippet should get you going in the right direction. It 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.

您可以使用任务计划程序每 x 分钟启动一次此批处理文件:

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

答案 2:

我一直很喜欢 Ritchie Lawrence 的批处理函数库.其中一个函数被称为 GetDirStats.

Answer 2:

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

GetDirStats 函数返回指定目录的文件数、子目录数和总大小.可能会很方便以供将来参考.虽然它只在 NT4/2000/XP/2003 上测试过.
只需将 compact/s 更改为 compact 即可不扫描子文件夹.

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天全站免登陆