[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 182
  • Last Modified:

windows batch script searching for long folder names

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"
  )
)  
0
icecom4
Asked:
icecom4
  • 2
2 Solutions
 
AustinComputerLabsCommented:
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:

From:http://www.allenware.com/mcsw/bus.htm#LongFileNames

I have used this successfully.

So just like in your question the call out would be "qagaming - battle quest"
good luck
0
 
rindiCommented:
Use Quotes for the Folder, like you used for your Question: "qagaming - battle quest".
0
 
icecom4Author Commented:
holy jesus that was easy.  let me test it.
0
 
icecom4Author Commented:
Thanks guys.  This worked, and as usual I learned something.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now