镜像文件夹,带有轻微的修改

发布于 2025-02-11 08:38:29 字数 362 浏览 4 评论 0原文

我必须“几乎”镜像两个文件夹。 一个文件夹包含具有文件格式的工具的输出 *_Output.txt。随着工具的运行,此处不断添加文件,并且将产生数十万个文件。 另一个应该包含与另一个工具的输入相同的文件,但是该工具期望格式为 *_input.txt

我的当前解决方案是a powershell 脚本,该脚本通过第一个文件夹循环,请检查是否已重命名的文件存在,如果不存在,则使用copy-item复制和重命名。但是,一旦文件编号足够高,这证明这将非常低效。我想改善这一点。

是否可以以某种方式利用Robocopy的 /mir并在第二个文件夹中重命名文件?我想防止如果存在更名的文件,请防止镜像。

有可能吗?

I have to "almost" mirror two folders.
One folder contains the output from a tool with the file format *_output.txt. Files are continuously added here as the tool runs and it will produce hundreds of thousands of files.
The other one should contain the same files as input for another tool, but that tool expects the format to be *_input.txt

My current solution is a powershell script that loops through the first folder, checks if the renamed file exists and if it doesn't, copies and renames it with Copy-Item. This, however, is proving very inefficient once the file number goes high enough. I would like to improve this.

Is it possible to somehow make use of robocopy's /MIR and also rename files in the second folder? I would like to prevent the original files being mirrored if a renamed file exists.

Is such a thing possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌面超妹 2025-02-18 08:38:29

您可以使用filesystemwatcher:

$watcher = New-Object -TypeName System.IO.FileSystemWatcher -Property @{Path='c:\temp\lib'; Filter='*_output.txt'; NotifyFilter=[IO.NotifyFilters]::FileName, [IO.NotifyFilters]::LastWrite};
Register-ObjectEvent -InputObject $watcher -EventName Created  -Action {Copy-Item $event.SourceEventArgs.FullPath $($event.SourceEventArgs.FullPath.Replace("output","input"))};
$watcher.EnableRaisingEvents = $true

You could use FileSystemWatcher:

$watcher = New-Object -TypeName System.IO.FileSystemWatcher -Property @{Path='c:\temp\lib'; Filter='*_output.txt'; NotifyFilter=[IO.NotifyFilters]::FileName, [IO.NotifyFilters]::LastWrite};
Register-ObjectEvent -InputObject $watcher -EventName Created  -Action {Copy-Item $event.SourceEventArgs.FullPath $($event.SourceEventArgs.FullPath.Replace("output","input"))};
$watcher.EnableRaisingEvents = $true
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文