The only caveat with ForFiles is that it only runs locally, meaning that you cannot use it to select and execute commands on files stored in a network folder. However, it is possible to complete this task if you map the network folder on Windows 10 and then run the command in the mapped drive. You can even create a script to schedule a task to run the command automatically. In this guide, you will learn the steps to use the ForFiles command on a shared network folder on Windows 10.
How to use ForFiles command on network folder on Windows 10 How to schedule ForFiles command on network folder on Windows 10
How to use ForFiles command on network folder on Windows 10
To delete files on a network shared folder with ForFiles, use these steps: Once you complete the steps, the command will run in the network location you specified. In the command, change “z” for the drive letter you want to assign to the mapping and replace “\networkShare\files” for the shared folder path. In the command, change “C:\PATH\TO\FOLDER” for the path to the folder that you want to delete files, and change /d -30 to select files with a last modified date. ForFiles delete files network folder In the command, replace “z” for drive letter that corresponds to your mapping.
ForFiles options breakdown
Here are the descriptions of the options used with the ForFiles command in this guide:
/p — indicates the pathname to start searching. /s — instructs ForFiles to search inside subdirectories. /d — specifies the last modified date for a file. /c — instructs ForFiles to execute command, which needs to be wrapped in double-quotes, the default is “cmd /c del @file”. /q — allows to delete folders without requiring confirmation.
If you want to learn more about these switches, use the ForFiles /? Command.
How to schedule ForFiles command on network folder on Windows 10
If you want to automate the process of deleting files with ForFiles, you first need to create a script and then execute it with a scheduled task using the Task Scheduler. To delete files on a network shared folder automatically, use these steps: After you complete the steps, the task will run on the schedule to remove the files in the network location that are older than the number of days you specified. Task Scheduler create new folder Task Scheduler create new task Task Scheduler general settings Schedule ForFiles task Task Scheduler ForFiles script location
Allow task to be run on demand. Run task as soon as possible after a scheduled start is missed. If the task fails, restart every.
Task Scheduler task settings This guide is focus on deleting files that meet certain criteria from a network folder, but this is an example. You can use ForFiles to run many other commands. All content on this site is provided with no warranties, express or implied. Use any information at your own risk. Always backup of your device and files before making any changes. Privacy policy info.