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. No comments yet.
  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: