Delete and Rename Folder Windows Batch Script

I was doing a task and I noticed that I was repeatedly deleting and renaming a folder in windows. I'm running a process that makes a backup of a folder and then do some update on an existing one. Whenever I wanted to restore the original (backed-up) folder, I would delete the existing one and rename the original.

I got a little tired and created a small batch file that would do this for me automatically. Here goes...

 

IF EXIST "SomeFolder-Backup" GOTO DELETEANDRENAME
EXIT
:DELETEANDRENAME
rmdir /S /Q "SomeFolder"
ren "SomeFolder-Backup" "SomeFolder"

"Save this as a .bat file"

What the above code does is it checks if the backup folder exists. If it doesn't then it would just exit the batch script. If it the backup folder exists then it removes the modified folder (SomeFolder) and then restores the backup folder. Hmmm...  I wish I could explain better. Anyway, if you're on the same situation then I'm sure you'll understand. If it does help, please drop a comment below!

 

Disclaimer: I will not be responsible for any damage done to your file system by running this script. Before using this simple script, make sure you understand what it does and what you want to do. Use at your own risk!

Published 08-11-2010 4:51 AM by lamia
Filed under: