- 1 year ago
Batch file commands to remove files from network drive
To remove files from a network drive using a batch file, you can use the del
command, which is used to delete files. Here's a simple batch script to remove files from a network drive:
batch@echo off
set "network_drive=\\server\share\path" <-- Replace with your network drive path
rem Remove all files with a specific extension (e.g., .txt)
del /s /q "%network_drive%\*.txt"
rem Remove specific files by name (e.g., file1.txt and file2.txt)
del /s /q "%network_drive%\file1.txt"
del /s /q "%network_drive%\file2.txt"
echo All files have been removed from the network drive.
pause
In this batch script, we first set the network_drive
variable to the path of your network drive. Replace \\server\share\path
with the actual path of your network drive. The del
command is then used to delete files from the specified network drive.
/s
: Deletes files from all subdirectories as well./q
: Quiet mode (no confirmation prompt).
You can customize the batch file to remove specific files or files with specific extensions by modifying the del
command accordingly.
Important Note: Be cautious when using the del
command, especially with the /s
option, as it will delete files without confirmation. Make sure you are absolutely certain about the files you want to delete before running the batch file.
Save the batch file with a .bat
extension, and double-click it to execute the commands and remove the files from the network drive.