using a partial file name and wildcard in a batch file

Posted on 2012-09-13
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?

Question by:PAdocIT
    LVL 51

    Accepted Solution

    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

    LVL 5

    Author Closing Comment

    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.
    LVL 51

    Expert Comment

    by:Bill Prew
    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.

    LVL 5

    Author Comment

    No problem. I just ran /? and figured out /Q would take care of that. Thanks again.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    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 …
    Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now