Home > Uncategorized > Delete Files/Folders with Robocopy

Delete Files/Folders with Robocopy

To create a batch file to have Robocopy delete the folder, create a text file called DelFolder.bat containing the following code:

@echo off
if {%1}=={} @echo Syntax: DelFolder FolderPath&goto :EOF

if not exist %1 @echo Syntax: DelFolder FolderPath – %1 NOT found.&goto :EOF
setlocal
set folder=%1
set MT=”%TEMP%\DelFolder_%RANDOM%”

MD %MT%
RoboCopy %MT% %folder% /MIR
RD /S /Q %MT%
RD /S /Q %folder%

endlocal

The usage of this batch file is: DelFolder.bat PathToDelete

Advertisements
Categories: Uncategorized
  1. November 28, 2017 at 15:59

    Dear Chris, My name is Peter from Ponticello in Torquay, England. I have been using this little script for what seems like years. Working on Server2012R2 today (28/11/17) I used the script to delete a set of folders which were nested too deeply for Windows to cope with. Windows file manager was unable to delete the folders.

    Your script is extremely useful, well written and it does exactly what it says on the tin. Thank you for making my job a little bit easier.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: