尽管ForFiles 命令(ForFiles command)在本地运行,但您可以在共享网络或Windows 10上的映射驱动器上使用它。如果您想在Windows 10的共享网络上安排ForFiles命令,您可以借助任务计划程序(Task Scheduler)。由于您无法独立运行命令,因此需要在任务计划程序(Task Scheduler)中创建任务之前单独创建它。
我们已经展示了创建 .bat 脚本以删除超过六个月的某些文件的步骤,以供您参考。但是,您可以根据自己的要求对其进行自定义。
首先,打开记事本(Notepad)或计算机上的任何其他文本编辑器,然后粘贴以下文本:
net use G: \\network-folder-path
ForFiles /p "G:" /s /d -180 /c "cmd /c del /q @file"
net use G: /delete
在保存之前,您必须对上述行进行一些更改。例如,在第一行中,您必须通过替换network-folder-path(network-folder-path) 文本输入驱动器号或网络驱动器以及要删除的确切文件夹 路径。
在第二行中,将 G 替换为原始驱动器号, 将180 替换为您想要的时间。它以日格式计算。
在第三行中,将驱动器号替换为原始驱动器号。完成后,单击“ File > Save As ”按钮。
然后,选择一个扩展名为 .bat 的文件,从 保存类型 (Save as type )下拉列表中 选择所有文件 ,然后单击(All Files )保存 (Save )按钮。之后,您可以将 .bat 文件移动到某个位置并保留在那里。
完成上述步骤后,您可以使用 Task Scheduler 创建任务(create the task using Task Scheduler)。
如何在共享网络(Shared Network)驱动器上安排ForFiles命令
要在Windows 10(Windows 10)中的共享网络上安排ForFiles命令,请执行以下步骤:
- 搜索任务计划程序(task scheduler)并单击单个结果。
- 单击创建任务(Create Task) 按钮。
- 输入名称 >从配置(Configure)列表中选择Windows 10 。
- 切换到触发器(Triggers)选项卡 > 单击新建(New)按钮。
- 从开始任务(Begin the task)下拉列表中选择按计划。(On a schedule)
- 选择每月(Monthly)选项 > 设置日期 > 单击确定(OK)。
- 切换到“操作(Actions)”选项卡 > 单击“新建”(New)按钮。
- 单击浏览( Browse)按钮 > 选择 .bat 脚本。
- 重复单击确定(OK)按钮以保存更改。
要开始,请搜索 任务计划程序(task scheduler) 并单击单个结果以在您的计算机上打开任务计划(Task Scheduler)程序应用程序。选择左侧的 任务计划程序库 (Task Scheduler Library ),然后单击 右侧的创建任务 选项。(Create Task )
为您的任务输入一个名称,并确保 在配置 (Configure for )下拉列表中选择了Windows 10 选项 。
切换到 触发器 (Triggers )选项卡,然后单击 新建 (New )按钮为您的任务创建一个新触发器。
现在, 从 Begin the task 下拉列表中 选择On a schedule ,选择(On a schedule )Monthly,然后选择日期和月份。
单击 确定 (OK )按钮,切换到 操作 (Actions )选项卡,然后单击 新建 (New )按钮为您的任务创建操作。
确保 在操作 (Action )下拉列表中选择了启动程序 (Start a program )选项 。然后,单击“ 浏览 (Browse )”按钮,并选择您之前创建的 .bat 脚本。
单击 确定 (OK )按钮以保存更改。
您应该打开一项重要设置。错过 预定开始后尽快运行任务(Run task as soon as possible after a scheduled start is missed)。假设您的计算机在特定日期的特定时间无法运行计划任务。如果启用此设置,它将在有时间时运行任务,然后是错过的计划。
您可以在“设置” (Settings )选项卡中找到此选项 。您只需在复选框中打勾,然后单击“ 确定 (OK )”按钮。
只要您不删除脚本或更改网络驱动器号,您就可以使用此方法在Windows 10上的共享网络文件夹上调度ForFiles命令。
How to schedule ForFiles command on Shared Network drive
Although the ForFiles command runs locally, you can use it on a shared network or mapped drive on Windows 10. If you want to schedule ForFiles command on a shared network in Windows 10, you can take the help of Task Scheduler. As you cannot run the command independently, it is required to create it separately before creating a task in Task Scheduler.
We have shown the steps to create a .bat script to delete certain files older than six months for your information. However, you can customize it as per your requirements.
To get started, open the Notepad or any other text editor you have on your computer and paste the following text:
net use G: \\network-folder-path
ForFiles /p "G:" /s /d -180 /c "cmd /c del /q @file"
net use G: /delete
Before saving, you have to make a few changes in the aforementioned lines. For example, in the first line, you have to enter the drive letter or network drive and the exact folder path you want to delete by replacing the network-folder-path text.
In the second line, replace G with the original drive letter and 180 with the time you want. It is being calculated in day format.
In the third line, replace the drive letter with your original drive letter. Once done, click on the File > Save As button.
Then, choose a file with .bat extension, select All Files from the Save as type drop-down list, and click the Save button. After that, you can move the .bat file to a place and keep it there.
Once you are done with these aforementioned steps, you can create the task using Task Scheduler.
How to schedule ForFiles command on Shared Network drive
To schedule ForFiles command on a shared network in Windows 10, follow these steps:
- Search for task scheduler and click on the individual result.
- Click on the Create Task button.
- Enter a name > choose Windows 10 from Configure for list.
- Switch to the Triggers tab > click the New button.
- Choose On a schedule from Begin the task drop-down list.
- Choose Monthly option > set date > click OK.
- Switch to the Actions tab > click the New button.
- Click the Browse button > select the .bat script.
- Click the OK buttons repeatedly to save the change.
To get started, search for task scheduler and click on the individual result to open the Task Scheduler app on your computer. Select the Task Scheduler Library on the left side and click on the Create Task option on the right side.
Enter a name for your task and make sure that the Windows 10 option is selected in the Configure for drop-down list.
Switch to the Triggers tab, and click on the New button to create a new trigger for your task.
Now, choose On a schedule from the Begin the task drop-down list, select Monthly, and choose a date and month.
Click the OK button, switch to the Actions tab, and click on the New button to create the action for your task.
Make sure the Start a program option is selected in the Action drop-down list. Then, click on the Browse button, and choose the .bat script you created earlier.
Click on the OK button to save the change.
There is one important setting you should turn on. It is called Run task as soon as possible after a scheduled start is missed. Let’s assume that your computer fails to run a scheduled task at a particular time on a specific date. If you enable this setting, it will run the task whenever it gets time, followed by the missed schedule.
You can find this option in the Settings tab. All you need to is to make a tick in a checkbox and click the OK button.
As long as you do not delete the script or change the network drive letter, you can use this method to schedule the ForFiles command on a shared network folder on Windows 10.