Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Trying to delete all files with certain extensions

73 views
Skip to first unread message

Docfxit

unread,
Jul 29, 2017, 9:19:51 PM7/29/17
to
I would like to delete all *.log files from the root of C: through all folders.
This code isn't deleting all *.log files.

del deleteTmp.bat
> file.txt echo/*.tmp
>> file.txt echo/*._mp
>> file.txt echo/*.log

for /f "delims=" %%a in (file.txt) do >>DeleteTmp.bat echo del /F /S "c:\%%a >> Delete.log"
Call DeleteTmp.bat
cmd

It also isn't writing out the Delete.log file.

Can anyone help me figure out why?

Thanks,

Docfxit

JJ

unread,
Jul 30, 2017, 10:14:07 AM7/30/17
to
Any file which can't be deleted means that it's being used by an application
(i.e. it's still opened for reading and/or writing).

There's a tool to close opened file by other applications, and it can be
automated. But those applications would still think that the files is still
opened, and they may crash or freeze because of that.

Docfxit

unread,
Jul 30, 2017, 2:30:33 PM7/30/17
to
Thanks for the reply...

I have 51 files and 4 directories. I don't think all of them are opened files. Although I don't know for sure. I will try to find the program that will unlock files. I currently use a program called Unlocker but I don't think I can use that in a batch file.

Do you have any idea why It also isn't writing out the Delete.log file?

Thanks,
Docfxit

John Gray

unread,
Jul 30, 2017, 3:42:03 PM7/30/17
to
What's wrong with
del c:\*.log /s
?
The Del command doesn't give a log, anyway...

Todd Vargo

unread,
Jul 31, 2017, 12:13:02 AM7/31/17
to
If you insert a PAUSE before the CALL line to verify the contents of
DeleteTmp.bat, you would find that its contents are not what you expect.

I get the following contents in DeleteTmp.bat

del /F /S "c:\*.tmp >> Delete.log"
del /F /S "c:\*._mp >> Delete.log"
del /F /S "c:\*.log >> Delete.log"

Its not deleting the files and not putting anything in Delete.log
because everything in the quotes in DeleteTmp.bat are being treated as a
complete fimename. Also the Delete.log is a poorly chosen name as it
falls into the scope of *.log which can not be deleted because the file
is in use.

To solve this problem, remove both dbl-quotes and properly escape the
redirection with ^>^>.

Personally, I would reduce the entire thing down to just one line and
eliminate all of the temp files. KISS.

del /F /S c:\*.tmp c:\*._mp c:\*.log > Delete.log 2>nul

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

Todd Vargo

unread,
Jul 31, 2017, 12:22:52 AM7/31/17
to
It does with /S switch. Try it.

Docfxit

unread,
Aug 1, 2017, 12:08:00 PM8/1/17
to
This is working really great. Thank you very much.

del /F /S c:\*.tmp c:\*._mp c:\*.log > "%~f0"CleanTempDeletedFiles.txt 2>nul

The only thing that isn't the greatest is in the deletedfiles.txt file it's showing the files that do get deleted saying they are deleted. The files that are in use or have Accesses denied show the file name with no reason.

It would be nice to see "Not accessible" by the files that don't get deleted.

The delete cmd is working great.

Thanks,
Docfxit

Todd Vargo

unread,
Aug 1, 2017, 8:51:46 PM8/1/17
to
On 8/1/2017 12:07 PM, Docfxit wrote:
>
> This is working really great. Thank you very much.
>
> del /F /S c:\*.tmp c:\*._mp c:\*.log > "%~f0"CleanTempDeletedFiles.txt 2>nul
>
> The only thing that isn't the greatest is in the deletedfiles.txt file it's showing the files that do get deleted saying they are deleted. The files that are in use or have Accesses denied show the file name with no reason.
>
> It would be nice to see "Not accessible" by the files that don't get deleted.
>
> The delete cmd is working great.

I'm not sure if this will give what you want but try changing
2>nul to 2>1 and see if any messages are reported.
0 new messages