Batch file to delete all files

I Need to come up with a batch file that will delete all files in the following two directories:

Delete all existing log files in \Windows\Temp directory

Delete all the \Windows\Logs\CBS\CbsPersist*.cab and log files (CBSPersist_%date%.cab and some CBSPersist_%date%.log)

\Windows\Logs\CBS\CBS.log file

Looking for the easiest why to do this, I can create a powershell script that will handle this but is there another way?

There is a way to do this using ActionScript and I’ve done it in the past using appendfile and concatenate to construct a batch file on the fly based on the individual values of the folders on each individual system then run the batch file.

delete __appendfile
if {exists files whose (name of it ends with ".log") of folder "Temp" of folder (pathname of windows folder)}
appendfile del /Q { concatenation "%0d%0adel /Q " of (pathnames of files whose (name of it ends with ".log") of folder of folder "Temp" of folder (pathname of windows folder))}
endif
if {exists files whose (name of it ends with ".log" OR name of it ends with ".cab") of folder "Logs\CBS" of folder (pathname of windows folder)}
appendfile del /Q { concatenation "%0d%0adel /Q " of (pathnames of files whose (name of it ends with ".log" OR name of it ends with ".cab") of folder "Logs\CBS" of folder (pathname of windows folder))}
endif
move __appendfile clean.bat
waithidden clean.bat

NOTE: I think this is a very hamfisted script but it should get you going.

2 Likes

Hello rkurowski,

The script you need is simple:

echo Batch to delete file

del “C:\Windows\Logs\CBS\CbsPersist*.cab” /s /f /q

del “C:\Windows\Logs\CBS\CbsPersist*.log” /s /f /q

del “C:\Windows\Logs\CBS\Cbs*.log” /s /f /q

echo Done!

You can play with the path to arrange with your needs.

Source: http://www.get-itsolutions.com/create-batch-to-delete-file-cmd/

Best Regards