icecom4
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"
)
)
@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"
)
)
ASKER
hi, I dont see where you wrote dir /s in the script. Do you mean put that instead of del /s ?
thanks
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.
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.
ASKER
ok so you mean at the bottom I should have this...
dir /s "%%~P\*.tmp" >> output.txt
del /s /q "%%~P\*.tmp"
right?
dir /s "%%~P\*.tmp" >> output.txt
del /s /q "%%~P\*.tmp"
right?
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" & 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
)
)
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
)
)
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It was my mistake, i have added dir after the delete. but it has to be before delete. Check the my modified batch file
ASKER
this worked perfectly
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"
)
)