Page 1 of 1

Delete all files and folders and sub_folders expect some two folders

Posted: 17 Jan 2018 05:11
by naraen87
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

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

Posted: 17 Jan 2018 12:44
by aGerman

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