I am trying to get a batch file that will look in C:\users\public\desktop and then delete any duplicate shortcut links like Shortcut (1) but leave the original.

Can something like this work? where you look at what files are in the directory and if it matches the file and has (1) or (2) at the end delete it. Example:

  • myfilelink.lnk
  • myfilelink (1).lnk
  • myfile2.lnk
  • myfile2 (1).lnk

then delete the ones with (1) at the end?

This is what I have so far but im not sure how to look at %%a and see if it has a (1) in the string. Then if it does Delete it.

@echo off
for /R "C:\Users\user\Desktop\Testing" %%a in (*.lnk) do IF %%a
PAUSE
有帮助吗?

解决方案

Add /s if you want it to act recursively.

del "C:\users\public\desktop\*(1).lnk"
del "C:\users\public\desktop\*(2).lnk"

or this if you are sure of the match:

del "C:\users\public\desktop\*(?).lnk"
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top