0

I have a folder on my drive, which I regulary clean. It has only txt files with sql logs. How can I write batch script which is going to clean it when I run it ? What I mean is, I do not want to go to drive, look for the folder, etc. Just have a shortcut on my screen, which is going to turn batch script on.

I tried to write it myslef, and modify it a bit, but its not working.

`@echo off
set "search_folder=C:\path\to\folder"
for /f "delims=" %%f in ('dir /b /s /a-d "%search_folder%\*.txt"') do (
  type "%%f" | findstr /v /r "^[ ]*$" > temp.txt
  move /y temp.txt "%%f"
)`

it does not delete anything

Kamil
  • 11
  • There can be used also just `del /A /F /Q "C:\path\to\folder\*.txt"`. There is no batch file needed at all. A shortcut file – `.lnk` file as present on your desktop and in Window __Start__ menu – with property __Target__ being configured as `%SystemRoot%\System32\cmd.exe /D /C del /A /F /Q "C:\path\to\folder\*.txt"` is absolutely enough and makes it possible to configure property __Run__ with *Minimized*. See also my comments on [this question](https://stackoverflow.com/questions/75279813/how-to-silently-run-a-batch-file-every-5-minutes) if a scheduled task should be used for this purpose. – Mofi Feb 01 '23 at 08:48