Link to home
Start Free TrialLog in
Avatar of icecom4
icecom4Flag for United States of America

asked on

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"
  )
)
Avatar of rushtoshankar
rushtoshankar
Flag of United States of America image

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"
  )
)
Avatar of icecom4

ASKER

hi, I dont see where you wrote dir /s  in the script.  Do you mean put that instead of del /s ?

thanks
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.
Avatar of icecom4

ASKER

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

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

right?
Avatar of icecom4

ASKER

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"
  )
)
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
  )
)
Avatar of icecom4

ASKER

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.  
 
ASKER CERTIFIED SOLUTION
Avatar of rushtoshankar
rushtoshankar
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It was my mistake, i have added dir after the delete. but it has to be before delete. Check the my modified batch file
Avatar of icecom4

ASKER

this worked perfectly