Jump to content

cmd file to erase all, except one i want

Recommended Posts

hey friends :) its me again!

i need a simple cmd file which can erase same kind of files in a folder except the one i determine. and it must be as simple as it can be :) because i wanna rearrange according to my needs.

for example i wanna erase all *.jpeg files in %systemroot%\web\wallpaper except the one i wanna keep.

can you help me pls. :)

note:i have searched the forum and i've found similar topics but they were so complicated.

Link to comment
Share on other sites

well..since it's a picture format...why dont u rename that single wallpaper with JPEG extension into JPG and than u can freely delete all JPEG files coz this 1 is not JPEG anymore and it still remains like it is :)


u got





delete JPEG's only and JPG is untouched and still remains with same functions as JPEG files


for other files i dont wanna talk i'm newbie here wih CMD, REG's etc :w00t:

Edited by cyberhrc
Link to comment
Share on other sites

try something like this

@echo off
:: put the path to your files here
set pathto=E:\My Files\textfiles\test

:: put your file extension here
set extn=txt

:: put the filename without extension of the one you want keeping here
set tokeep=msfntest

pushd %pathto%
for %%a in (*.%extn%) do if "%%~a" neq "%tokeep%.%extn%" echo/del /q "%%~a"
popd&goto :eof

Remove the echo/ once you have verified it works.

Note - I have filled in after the equals symbols, only for information

Edited by Yzöwl
Link to comment
Share on other sites

hey friend (Yzöwl)

thank you very much for your help :) you're repling my two questions. as a matter of fact i wanted to thank you after trying your suggestions. but your quick responce made me so happy. :) and i didnt wanted to wait for a thank.

Link to comment
Share on other sites

I'm looking to do something similar to that in that I want to maintain a set of desktop icons (shortcuts) that are approved like 'My Documents' 'My Computer' 'Internet Explorer' 'Firefox' 'Real Player', etc. then if someone adds a shortcut or saves a file to the desktop to have it automatically deleted each time windows is booted (doesn't matter at which point).

I'm thinking I need to store the approved shortcut names in a file or somewhere in the actual command script and have some kind of command that compares the current desktop files/shortcuts to what's supposed to be there and if something doesn't match, Delete it...

Link to comment
Share on other sites

@ Thinkster

That shouldn't be necessary for most of the ones you've mentioned, as they are not shortcuts and will not be found in the Desktop folder.


Here is an example, however, of something you could use

@echo off&setlocal enableextensions

for /d %%a in ("%AllUsersProfile%\..\*") do if exist "%%~a\Desktop\*.lnk" call :gothere "%%~a\Desktop"
endlocal&goto :eof

pushd %1
for /f "delims=" %%b in ('dir /b/a-d "*.lnk"^|findstr/ivg:"%~dp0lnk2keep.txt"^2^>nul') do if errorlevel 0 del /q "%%~b"
popd&goto :eof

now you will need a txt file named lnk2keep.txt, to be kept in the same location as this cmd file. Each line of the txt file will contain the names of the files you wish to keep.


Real Player.lnk

With the above, all *.lnk files found on 'all users desktops' will be deleted unless they match the names listed in the text file.


Edited by Yzöwl
Link to comment
Share on other sites

i have wanted this except one file. can we extend this except two or three or ect. files ? what i wanna do is clean my wallpaper content except the ones i like.
Remove the ones you don't like from your install CD, then you won't need to worry about it at all.
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.

  • Create New...