Reputation: 942
I am looking for a way to delete all files in folder but except one folder through windows batch script..can you please help me on this.
Upvotes: 2
Views: 9515
Reputation: 210
Test this - it should work.
For EX:To remove all files and folder except cd folder inside abc
pushd "d:\abc\cd" && rd /s /q "d:\abc" 2>nul
Upvotes: 5
Reputation: 210
In windows powershell, Use the below command to remove all files and folder except one
Remove-Item c:\<Path to Folder>\* -exclude *<folder you don't want to remove>*
Upvotes: 2
Reputation: 5301
This lists all the files (and only the files) in the current directory:
for /r %%i in (*) do echo %%i
to delete a folder you can do:
RMDIR \"FOLDERNAME" /S /Q
you can compare two values in windows batch file as:
if NOT "%SubFolderName%" == "folder-name-you-do-not-want-to-delete"
// delete the folder.
I hope you can connect the dots...
Upvotes: 1