简体   繁体   English

添加文件夹中的新项目时,如何自动运行 bat 文件?

[英]What can I do to automatic run a bat file when a new item on a folder is added?

I have a ps1 file which contains the code and a bat file which when i double click runs the code.我有一个包含代码的 ps1 文件和一个 bat 文件,当我双击运行代码时。 The ps1 file renames all files in that folder. ps1 文件重命名该文件夹中的所有文件。 Here is the code:这是代码:

get-childitem -path C:\Users\ASUS\Videos\Downloads\*.mp4 | foreach {rename-item $_ $_.name.replace("_"," ")} 

How can I run the bat file to automatically rename all files that are added to that folder?如何运行 bat 文件以自动重命名添加到该文件夹的所有文件?

I saw @olaf mentioned FileSystemWatcher and, honestly, it one of the better options for what you're trying to do.我看到@olaf 提到了 FileSystemWatcher,老实说,它是您尝试做的更好的选择之一。

Alternatively, you can use Task Scheduler to run at specific times, dates, actions, etc. There's also no need to point to the bat file, it can run ps1 files just as easy without having to have.bat execute the.ps1.或者,您可以使用任务计划程序在特定时间、日期、动作等运行。也无需指向 bat 文件,它可以像运行 ps1 文件一样简单,而无需让 .bat 执行 .ps1。

Change your ps1 to the following.将您的 ps1 更改为以下内容。 It's passing only the items that were created less than 30 minutes ago;它只传递不到 30 分钟前创建的项目; can be changed to days, minutes, etc. Then, it's just renaming them(:可以更改为天,分钟等。然后,它只是重命名它们(:

Get-ChildItem -Path C:\Users\ASUS\Videos\Downloads\*.mp4 | Where-Object {$_.CreationTime -gt (Get-Date).AddMinutes(-30)}| foreach {rename-item $_.FullName $_.name.replace("_"," ")} 

暂无
暂无

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

相关问题 将文件添加到文件夹时运行 .bat 文件的 Powershell 脚本 - Powershell script to run a .bat file when a file is added to a folder 将电子邮件添加到共享文件夹后,如何运行脚本? - How do I Run a Script When Emails are Added to a Shared Folder? 如何使用bat文件从启动/自动启动文件夹运行Powershell脚本? - How can I run a powershell script from startup/autostart folder with bat file? 运行Powershell脚本时如何使.bat文件不退出? - How can I make a .bat file not exit when I run a powershell script? 如何让 Powershell 向 bat 文件提示符运行命令? - How do I get Powershell to run a command to a bat file prompt? 如何编写Powershell脚本来检查上次将文件添加到文件夹的时间? - How do I write a Powershell script that checks when the last time a file was added to a folder? 如何运行带有BAT文件中极长参数的程序? - How do I run a program with extremely long arguments from BAT file? 文件内容与文件夹名称不匹配时运行Powershell脚本 - Run a powershell script when file contents do not match folder names 我想通过.bat文件运行.ps1文件 - I want to run .ps1 file through a .bat file 我有一个.ps1文件,该文件从folder.fetch中提取文件夹内容。如何从jmeter运行该.ps1文件,以便进行性能测试? - i have a .ps1 file which fetch folder content from the folder.how to run that .ps1 file from jmeter so i can do performance testing?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM