- Thread Author
- #1
Hi,
I have a SSD with several partitions.
I need to work at J:\ and I need to delete everything inside J:\, except the following folders:
J:\System Volume Information
J:\$RECYCLE.BIN
J:\New
J:\Old Stuff
And the following sub-folders:
J:\Papers\Folder
J:\Room\Main Documents
J:\Year\Origin\Part
J:\Year\Origin\Part Two
After searching and reading a lot, I wrote the following code:
@echo OFF
SETLOCAL
SET "sourcedir=J:\"
SET "keepdir=System Volume Information"
SET "keepdir=$RECYCLE.BIN"
SET "keepdir=New"
SET "keepdir=Old Stuff"
SET "keepdir=Papers\Folder"
SET "keepdir=Room\Main Documents"
SET "keepdir=Year\Origin\Part"
SET "keepdir=Year\Origin\Part Two"
FOR /d %%a IN ("%sourcedir%\*") DO IF /i NOT "%%~nxa"=="%keepdir%" RD /S /Q "%%a"
GOTO :EOF
Unfortunately, the code above doesn't work (it deletes everything inside J:\).
Please, I will appreciate any help.
Thank you in advance!
I have a SSD with several partitions.
I need to work at J:\ and I need to delete everything inside J:\, except the following folders:
J:\System Volume Information
J:\$RECYCLE.BIN
J:\New
J:\Old Stuff
And the following sub-folders:
J:\Papers\Folder
J:\Room\Main Documents
J:\Year\Origin\Part
J:\Year\Origin\Part Two
After searching and reading a lot, I wrote the following code:
@echo OFF
SETLOCAL
SET "sourcedir=J:\"
SET "keepdir=System Volume Information"
SET "keepdir=$RECYCLE.BIN"
SET "keepdir=New"
SET "keepdir=Old Stuff"
SET "keepdir=Papers\Folder"
SET "keepdir=Room\Main Documents"
SET "keepdir=Year\Origin\Part"
SET "keepdir=Year\Origin\Part Two"
FOR /d %%a IN ("%sourcedir%\*") DO IF /i NOT "%%~nxa"=="%keepdir%" RD /S /Q "%%a"
GOTO :EOF
Unfortunately, the code above doesn't work (it deletes everything inside J:\).
Please, I will appreciate any help.
Thank you in advance!