Reputation: 210
I tried to delete a files and folder inside a folder except one ,but so far I didn't get a perfect answer for it?
Can any one help on this above?
My folder structure seems like this:
I have ABC Folder under E:\ Inside that folder I have 4 files named A.txt,B.txt,C.txt & D.txt and I have 3 Folders in that they are AB , BC & CD ...I want to remove all files and folders in ABC folder except CD folder inside ABC folder..
Can any one please help on the above?
Upvotes: 2
Views: 5176
Reputation: 71
pushd "d:\abc\cd" && rd /s /q "d:\abc" 2>nul will delete all the files inside the folder cd.
Upvotes: 1
Reputation: 4689
Since you know exactly yout directory tree, you can just remove all element you don't need:
del e:\abc\ab\*.*
rmdir e:\abc\ab
del e:\abc\bc\*.*
rmdir e:\abc\bc
More general solution:
for /D %%d in (e:\abc\*) do if "%%d" neq "CD" rmdir "%%d"
Upvotes: 0
Reputation: 41234
Test this - it should work.
pushd "d:\abc\cd" && rd /s /q "d:\abc" 2>nul
Upvotes: 1