[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

delete and send output to .txt file to execution directory

Posted on 2011-10-21
10
Medium Priority
?
312 Views
Last Modified: 2012-05-12
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"
  )
)
0
Comment
Question by:icecom4
  • 5
  • 5
10 Comments
 
LVL 6

Expert Comment

by:rushtoshankar
ID: 37006717
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
 

Author Comment

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

thanks
0
 
LVL 6

Expert Comment

by:rushtoshankar
ID: 37006942
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:icecom4
ID: 37009562
ok so you mean at the bottom I should have this...  

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

right?
0
 

Author Comment

by:icecom4
ID: 37009570
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
 
LVL 6

Expert Comment

by:rushtoshankar
ID: 37009703
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
 

Author Comment

by:icecom4
ID: 37010451
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
 
LVL 6

Accepted Solution

by:
rushtoshankar earned 1000 total points
ID: 37011060
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
 
LVL 6

Expert Comment

by:rushtoshankar
ID: 37011064
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
 

Author Closing Comment

by:icecom4
ID: 37011575
this worked perfectly
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is only natural that we all want our PCs to be in good working order, improved system performance, so that is exactly how programs are advertised to entice. They say things like:            •      PC crashes? Get registry cleaner to repair it!    …
Issue: Unstable cursor in Windows XP and Windows runs extremely slow in that any click will bring up the Hour glass (sometimes for several seconds before giving you what you want) . Troubleshooting Process and the FINAL FIX: This issue see…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month17 days, 18 hours left to enroll

830 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