The Batch file below delete ALL of the shortcuts and their variants located in all the folders in "C:\Documents and Settings" folder:
@echo off
for /R "C:\Documents and Settings" %%a in (*.lnk) do del %%a
EDIT: New solution based on new information added
Ok. Lets suppose that there is a text file with the base names of the shortcuts to delete. For example, this is part of delete.txt file:
Accounts Payable
Approval Levels
Clinical Carestation
. . . . . .
Security
Snomed Coding
. . . . . .
The Batch file below delete all variants of the base names in previous list:
@echo off
for /F "delims=" %%a in (delete.txt) do (
for /R "C:\Documents and Settings" %%b in ("*%%a*.lnk") do echo del "%%b"
)
However, previous method have two problems:
The delete list must be created by hand every time the Batch program run because there is no way to know in advance which names the users will choose for their new shortcuts. If all shortcuts must be manually revised to select the names to delete (like before) the Batch program is just useless.
There is no way to separate a shortcut that must not be deleted from the variants that must be deleted. For example, "Security" base name allows to delete all these files: "Security.lnk", "Copy of Security.lnk", "Copy (2) of Security.lnk", "Security (2).lnk", et cetera, but it also delete "Windows Firewall with Advanced Security.lnk".
Now suppose that there is a text file with the full names of the shortcuts to preserve instead. For example, this is part of preserve.txt file:
Windows Firewall with Advanced Security
This file is created just once and must be modified only when a new permanent shortcut is created, so it is much easier to maintain than the previous delete list.
The Batch file below delete all existent shortcuts excepting the ones included in the preserve list.
@echo off
setlocal
for /F "delims=" %%a in (preserve.txt) do set preserve[%%a]=defined
for /R "C:\Documents and Settings" %%a in (*.lnk) do (
if not defined preserve[%%~Na] echo del "%%a"
)
Antonio
EDIT: Comment for Xaero
Excuse me. This is just a simple recommendation for your future questions...
You must realize that better questions lead to better answers. Perhaps there is a point in your question that is clear for you, but you must realize that we have not the same background to the topic than you, so you should try to read your own explanations with critical eye and provide the missing information. For example, when I asked you: "Where are the shortcuts named "copy of"... that you said?" you should realized that I asked that because those names don't appear in the list, not because I wanted to know the location of such files in the disk (that is precisely the purpose of the Batch file!). You should answered this question with something like: "Previous list have the base names only, the variants are assembled from they; for example: "Copy of Accounts Payable.lnk" or "Approval Levels (2).lnk". This simple answer would provided you with a right solution in less time, that ultimately is what you were looking for. Isn't it?
Antonio
EDIT: Comment for fthiella
Excuse me, no offense is intended in the following paragraphs.
People at this site expect to get reliable and precise answers for their questions. If you answer a question with the purpose of learn about it, then it is probable that you provide wrong or imprecise information.
I suggest you to master a theme before you try to provide solutions for it to other people. If you provide wrong answers to people with no experience, it is probable that they learn and use inadequate techniques. As a matter of fact, this is one of the reasons that have spread multiple bad habits in Batch file community (like using echo.
command to show empty lines, or for /F "tokens=* delims= " %%a in ('dir /b *.txt')
instead of for %%a in (*.txt)
, among others). There is a popular phrase in my country: "A one-eyed man leading blind people"...
Antonio