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

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

delete script which asks the user which hard drive to search

ok, so instead of searching drives C D and E, I want this script modified so that it asks the user what hard drive to search.  is that possible?  

@echo off                                            
set folder=
for %%D in (C D E) do (
  for /F "tokens=*" %%P in ('if exist %%D: dir /a:d /s/b %%D:\*qagame ^| findstr /L /E /i "\etmain"') do (
      del /s /q "%%~P\*.z"
  )
)
0
icecom4
Asked:
icecom4
  • 3
  • 3
1 Solution
 
Gerald26Commented:
@echo off                                            
echo Enter drives to search (separate with a space)
set /P Drive=
set folder=
for %%D in (%Drive%) do (
  for /F "tokens=*" %%P in ('if exist %%D: dir /a:d /s/b %%D:\*qagame ^| findstr /L /E /i "\etmain"') do (
      del /s /q "%%~P\*.z"
  )
)
0
 
icecom4Author Commented:
Hello, and thanks.  I forgot to ask, how can I consolidate deleting *.tmp, *~ and *~ in the same script?  Because right now I an just copying the above script and doing a new one for each extension I need deleted.  I think this is causing the script to take a long time.  
0
 
Gerald26Commented:
This would do it ?

@echo off                                            
echo Enter drives to search (separate with a space)
set /P Drive=
set folder=
for %%D in (%Drive%) do (
  for /F "tokens=*" %%P in ('if exist %%D: dir /a:d /s/b %%D:\*qagame ^| findstr /L /E /i "\etmain"') do (
      del /s /q "%%~P\*.z" & del /s /q "%%~P\*.tmp" & del /s /q "%%~P\*.~"
  )
)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Bill PrewCommented:
Can you describe what files from what locations you are trying to remove, there may be a simpler way.

~bp
0
 
icecom4Author Commented:
here is the script so far...

@echo off                                            
echo Enter drives to search (separate with a space)
set /P Drive=
set folder=
for %%D in (%Drive%) do (
  for /F "tokens=*" %%P in ('if exist %%D: dir /a:d /s/b %%D:\*qagame ^| findstr /L /E /i "\qagame"') do (
      del /s /p "%%~P\z*" & del /s /p "%%~P\*.tmp" & del /s /p "%%~P\~*"
  )
)

the only thing I noticed is that a bunch of output shows up on screen before it finds a file to delete and asks for confirmation i.e....file not found...over and over and over.  

its it possible to get ris of this output and only have the confirmation questions pop up?  

to billprew's question:
the folder is qagame but the directories vary because the program folders get installed all over the place for various reasons hence the search.  The files getting deleted are worthless temp files, and files beginning with ~ and z which are a long story, but to make it short those need to go also.  

0
 
icecom4Author Commented:
I forgot to mention, the drive confirmation works so thats for that.  I only want to get rid of the output in command window except for the delete confirmations....if possible.  
0
 
Gerald26Commented:
@echo off                                            
echo Enter drives to search (separate with a space)
set /P Drive=
set folder=
(for %%D in (%Drive%) do (
  for /F "tokens=*" %%P in ('if exist %%D: dir /a:d /s/b %%D:\*qagame ^| findstr /L /E /i "\etmain"') do (
      del /s /q "%%~P\*.z" & del /s /q "%%~P\*.tmp" & del /s /q "%%~P\*.~"
  )
))2>NUL

 :)

No more error !
 
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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