delete and send output to .txt file to execution directory

Hello, I have the below script which works fine.  How do I modify the script so that it provides an output to a text file of what it deletes?  The text can be dumped into the same directory where the script be being executed from.  I would also want both of the scripts below to go into the same .txt output.  

@echo off                                            
set folder=
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) 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\*.~"
  )
)

@echo off                                            
set folder=
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) do (
  for /F "tokens=*" %%P in ('if exist %%D: dir /a:d /s/b %%D:\*qugame ^| findstr /L /E /i "\etmain"') do (
      del /s /q "%%~P\*.tmp"
  )
)
icecom4Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rushtoshankarSr Manager Software DevelopmentCommented:
Modify the script as follows
Use dir /s command as del doesnt have verbose mode

---> echo. > output.txt <---
@echo off                                            
set folder=
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) do (
  for /F "tokens=*" %%P in ('if exist %%D: dir /a:d /s/b %%D:\*qagame ^| findstr /L /E /i "\etmain"') do (
--->      dir "%%~P\*.~" >> output.txt  <------
      del /s /q "%%~P\*.~"
  )
)

@echo off                                            
set folder=
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) do (
  for /F "tokens=*" %%P in ('if exist %%D: dir /a:d /s/b %%D:\*qugame ^| findstr /L /E /i "\etmain"') do (
--->      dir "%%~P\*.tmp" >> output.txt   <----
      del /s /q "%%~P\*.tmp"
  )
)
0
icecom4Author Commented:
hi, I dont see where you wrote dir /s  in the script.  Do you mean put that instead of del /s ?

thanks
0
rushtoshankarSr Manager Software DevelopmentCommented:
Dont remove the delete command. Add the line before the delete command.

check lines with ----> <---- mark.
I missed /s in dir command. Please add it.

Dir displays possible files to be deleted and redirects to output.txt and del command does the deletion.
You need to have both commands.
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

icecom4Author Commented:
ok so you mean at the bottom I should have this...  

      dir /s "%%~P\*.tmp" >> output.txt
      del /s /q "%%~P\*.tmp"

right?
0
icecom4Author Commented:
actually... let me give you the exact script I will be using.  Can you please add the output line to it.  Because I am not sure if I have to add a seperate line for each delete line as there are several.  

set folder=
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 /F "tokens=*" %%P in ('if exist %%D: dir /a:d /s/b %%D:\*qagame ^| findstr /L /E /i "\qagame"') do (
      del /s /q "%%~P\z*pk3" & del /s /q "%%~P\*.tmp" & del /s /q "%%~P\~*pk3" & del /s /q "%%~P\*.????????.pk3"
  )
)
0
rushtoshankarSr Manager Software DevelopmentCommented:
set folder=
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 /F "tokens=*" %%P in ('if exist %%D: dir /a:d /s/b %%D:\*qagame ^| findstr /L /E /i "\qagame"') do (
      del /s /q "%%~P\z*pk3" & dir /s "%%~P\z*pk3" >> output.txt & del /s /q "%%~P\*.tmp" & dir /s "%%~P\*.tmp" >> output.txt & del /s /q "%%~P\~*pk3" & dir /s "%%~P\~*pk3" >> output.txt & del /s /q "%%~P\*.????????.pk3" & dir /s "%%~P\*.????????.pk3" >> output.txt
  )
)
0
icecom4Author Commented:
the output gives a bunch of lines about volume info...
Volume in drive C is Windows_Ubuntu
 Volume Serial Number is 98C6-048F
 Volume in drive C is Windows_Ubuntu
 Volume Serial Number is 98C6-048F...

but nothing about deletions.  the deletions work though.  
 
0
rushtoshankarSr Manager Software DevelopmentCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rushtoshankarSr Manager Software DevelopmentCommented:
It was my mistake, i have added dir after the delete. but it has to be before delete. Check the my modified batch file
0
icecom4Author Commented:
this worked perfectly
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows XP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.