Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

using a partial file name and wildcard in a batch file

Posted on 2012-09-13
4
Medium Priority
?
4,877 Views
Last Modified: 2012-09-13
I have a batch file that does a number of tasks and the last task is to do some cleanup. I need to be able to delete an already existing shortcut from users desktops. Unfortunately the shortcut will be partially named differently for every user. For example the beginning of the shortcut will be the same however the user's username is appended to their shortcut, so application - username.lnk. Can you do something like application - *.lnk?

Thanks.
0
Comment
Question by:PAdocIT
  • 2
  • 2
4 Comments
 
LVL 59

Accepted Solution

by:
Bill Prew earned 1500 total points
ID: 38395036
Yes, you certainly can.  For a test just do a command like this from their desktop directory.

DIR "application-*.lnk"

Open in new window

That should work, so you can do something like this to remove the file.

DEL /Y "%USERPROFILE%\Desktop\application-*.lnk"

Open in new window

~bp
0
 
LVL 5

Author Closing Comment

by:PAdocIT
ID: 38395109
I think the quotes around the file name is where I went wrong. Initially my test consisted of a notepad shortcut name notepad - username.lnk. When I tried notepad - *.lnk it deleted every shortcut on my desktop. lol

Also just as an FYI "y" doesn't appear to be a valid switch for DEL.

Anyway, thanks for the help.
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 38395213
Thanks, glad that helped.  Yes, anytime you have a filename or path with spaces in it, the quotes are needed.

Sorry about the switch, on many commands the /Y forces a "yes" response when it would normally be prompted for.  DEL is a little different, it uses /Q for that.

~bp
0
 
LVL 5

Author Comment

by:PAdocIT
ID: 38395424
No problem. I just ran /? and figured out /Q would take care of that. Thanks again.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question