Discussion Locked

Batch file.

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I need to create a batch file that i can execute from one machine, which will be able to delete all the files/folders in a specific folder on multiple network machines. Obviously i will need to include the comp name/path etc. Is this possible and if so what is the syntax?

Thank you

6 replies

by don christner

First of all, make sure that you have the required perms on the computer you try to erase files from. Then in the batch file you will need the following command:

erase \\computername\c\temp\*.* /Q /S

Don

by don christner

The above example erases all files from all folders in the c:\temp folder ( the /s option) without asking if it should erase each file (the /q option).

If you want more details about various options of the erase command, go to a DOS prompt and type erase /?.

by blackcurrant

Another option is to map the drives that you need to access, note the drive letters assigned to each 'drive' and include them in your statement:

@echo off
del F:\sharename\*.*
del G:\sharename\*.*
del J:\sharename\*.*
exit

Write this out in notepad and save it as a .bat file on the computer where you have mapped the drives. 'del' is the command to delete, and '*.*' means all files. '@echo off' prevents each command from appearing in a DOS box. 'Exit' tells the system that the batch file has finished and the DOS session can be closed.

Next create a shortcut to the batch file. Once created, right click the file and select properties. Make sure that close on exit is selected and that it is set to run minimised.

The syntax described above is fine if you only need to delete the files from that computer. If you need to delete the files from any computer you will need to use the computername that follows the \\ symbols you see in explorer, as given in the first answer, and save the batch file to a shared folder that then be accessed from any computer on your network.

Have fun.

This discussion is closed to new replies.