gpt4 book ai didi

batch-file - 将新文件添加到文件夹时执行批处理文件

转载 作者:行者123 更新时间:2023-12-03 10:03:26 25 4
gpt4 key购买 nike

我正在使用下面从 batch file to monitor additions to download folder 获得的批处理文件示例.我想修改它,以便它循环遍历所有子文件夹。

有人对如何做到这一点有任何想法吗?

@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

最佳答案

拜托....让它成为powershell?

http://archive.msdn.microsoft.com/PowerShellPack包含函数 Start-FileSystemWatcher

请不要在任何系统上使用这个批处理文件。


Powershell.com有 sample

这是来自 this thread 的示例:

$folder = '<full path to the folder to watch>'
$filter = '*.*' # <-- set this according to your requirements
$destination = '<full path to the destination folder>'
$fsw = New-Object IO.FileSystemWatcher $folder, $filter -Property @{
IncludeSubdirectories = $true # <-- set this according to your requirements
NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'
}
$onCreated = Register-ObjectEvent $fsw Created -SourceIdentifier FileCreated -Action {
$path = $Event.SourceEventArgs.FullPath
$name = $Event.SourceEventArgs.Name
$changeType = $Event.SourceEventArgs.ChangeType
$timeStamp = $Event.TimeGenerated
Write-Host "The file '$name' was $changeType at $timeStamp"
Move-Item $path -Destination $destination -Force -Verbose # Force will overwrite files with same name
}

最后,注销订阅:Unregister-Event -SourceIdentifier FileCreated

关于batch-file - 将新文件添加到文件夹时执行批处理文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5923802/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com