Batch file to delete sub folder if exist and else batch file should create new folders?

i need a Batch file to delete Sub folder in a folder if exist else batch file should create new sub folders in Mainfolder?

2

1 Answer

@echo off
set SF=PathToSubFolder
if not "%~1"=="" set SF=%~1
if exist "%SF%" ( ECHO Sub folder found. Deleting . . . RD /S /Q "%SF%"
) else ( ECHO Sub folder not found. Creating . . . MKDIR "%SF%"
)
ECHO Completed.

If you save that as CheckSub.bat you can either edit the file to set the subdirectory, or you can run it from another batch file or command prompt window with the command: call CheckSub.bat "C:\Path\To\Sub\Folder" (if you call it that way it overwrites whatever you set in the file

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like