windows batch script searching for long folder names

Posted on 2011-10-22
Last Modified: 2012-06-22
I have this script below.  It searches for a certain directory and then runs a few tasks.  How can I run these same tasks on a folder with a long file name?  For instance, in the scipt the folder that it seaches for is called "qagame".  But I need to use this for a folder called "qagaming - battle quest".  I have tried using qagame~1 but the script does not find anything.  

If you can help, please edit the script and re post.  Thanks in advance.  

@echo off                                            
set folder=
rem for %%D in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
for %%D in (C) do (
  for /F "tokens=*" %%P in ('if exist %%D: dir /a:d /s/b %%D:\*qagame ^| findstr /L /E /i "\qagame"') do (
     dir /s "%%~P\z*pk3" >> output.txt
     del /s /q "%%~P\z*pk3"
     dir /s "%%~P\*.tmp" >> output.txt
     del /s /q "%%~P\*.tmp"
     dir /s "%%~P\~*pk3" >> output.txt
     del /s /q "%%~P\~*pk3"
     dir /s "%%~P\*.????????.pk3" >> output.txt
     del /s /q "%%~P\*.????????.pk3"
Question by:icecom4
    LVL 13

    Accepted Solution

    Long file or folder names that contain  Space s must be enclosed in "double-quotes" when used in Batch commands. If you don't do this, each fragment of the file or folder name is treated as a separate parameter. You also need to "quote" any long file or folder names passed as command-line parameters, for example:


    I have used this successfully.

    So just like in your question the call out would be "qagaming - battle quest"
    good luck
    LVL 87

    Assisted Solution

    Use Quotes for the Folder, like you used for your Question: "qagaming - battle quest".

    Author Comment

    holy jesus that was easy.  let me test it.

    Author Closing Comment

    Thanks guys.  This worked, and as usual I learned something.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    There are 2 things you must have in order to connect to the internet behind a router, The "Gateway IP" of the router, which is usually something like, I've seen routers with default values of:,,, …
    Are you unable to synchronize your OST (Offline Storage Table) file with Microsoft Exchange Server? Is your OST file exceeding 2 GB size limit? In Microsoft Outlook 2002 and earlier versions, there is a 2 GB size limit for the OST file. If the file …
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    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…

    760 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

    8 Experts available now in Live!

    Get 1:1 Help Now