bonky
Member
- Local time
- 12:59 AM
- Posts
- 24
- OS
- win10
Hello all.... i have a request for help....
Im trying to delete all files & directories except three files, in my search in google I came across this
(for /f "tokens=*" %f in ('dir /a:-d /b 2^>nul ^| findstr /v /b /e /c:"test1.txt"') do (del /f "%f")) & (for /f "tokens=*" %f in ('dir /a:-d /b 2^>nul ^| findstr /v /b /e /c:"test1.txt"') do (rmdir /q /s "%f"))
it works... BUT.... I have to be already in that directory (CD\ etc etc) is it poss to ajust this script to delete no matter where i am for the "%userprofile%\downloads\test" ?
also to add another two files to this not to be touched (I know I can attrib +r, but would like to have one line command if poss)
Im trying to delete all files & directories except three files, in my search in google I came across this
(for /f "tokens=*" %f in ('dir /a:-d /b 2^>nul ^| findstr /v /b /e /c:"test1.txt"') do (del /f "%f")) & (for /f "tokens=*" %f in ('dir /a:-d /b 2^>nul ^| findstr /v /b /e /c:"test1.txt"') do (rmdir /q /s "%f"))
it works... BUT.... I have to be already in that directory (CD\ etc etc) is it poss to ajust this script to delete no matter where i am for the "%userprofile%\downloads\test" ?
also to add another two files to this not to be touched (I know I can attrib +r, but would like to have one line command if poss)
My Computer
System One
-
- OS
- win10
- Computer type
- PC/Desktop




