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

1
  • 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 if a scheduled task should be used for this purpose. Commented Feb 1, 2023 at 8:48

1 Answer 1

0
  1. This is how you schedule a batch https://www.thewindowsclub.com/how-to-schedule-batch-file-run-automatically-windows-7
  2. Code to delete bunch of files https://thegeekpage.com/how-to-delete-all-particular-files-inside-a-folder-in-windows-10/
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.