Delete all files and folders and sub_folders expect some two folders

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
naraen87
Posts: 17
Joined: 21 Dec 2017 06:41

Delete all files and folders and sub_folders expect some two folders

#1 Post by naraen87 » 17 Jan 2018 05:11

Say for Example my folder Structure looks like the below one

full_delete=E:\Oracle\Middleware\user_projects\domains\Skandia\servers\AdminService\
expection_folder=E:\Oracle\Middleware\user_projects\domains\Skandia\servers\Extranet-server\

I've to delete all the filea subfolders and folders that are available in the %full_delete%

I used the code

Code: Select all

pushd "%pathtofolder%" && (rd /s /q "%pathtofolder%" 2>nul & popd)
Now I want to do the same thing for %expection_folder% but in this I have to give exception for stage and security sub-folders and the files and folders contents that available under those stage and security folders

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Delete all files and folders and sub_folders expect some two folders

#2 Post by aGerman » 17 Jan 2018 12:44

Code: Select all

@echo off &setlocal
pushd "E:\Oracle\Middleware\user_projects\domains\Skandia\servers\Extranet-server"
for /f "delims=" %%i in ('dir /ad /b^|findstr /vlix "stage security"') do ECHO rd /s /q "%%i"
popd
PAUSE
If the right folders to delete are displayed then remove ECHO and PAUSE.

Steffen

Post Reply