Ordner mit Datum im Namen löschen

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Onkel Uli
Posts: 1
Joined: 07 Sep 2017 15:09

Ordner mit Datum im Namen löschen

#1 Post by Onkel Uli » 07 Sep 2017 15:17

Guten Abend,
ich sichere Daten in Ordner mit Datum als Name. JJJJ-MM-TT
Ich möchte alle Ordner inkl. Unterordner, bis auf die letzten 20 löschen.

Wie ist der richtige Code. Ich arbeite mit Win8 und Win10

Viele Dank
OU

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Ordner mit Datum im Namen löschen

#2 Post by aGerman » 07 Sep 2017 15:44

Users from all over the world attend this forum. In order to let everybody understand the forum content the common language is English.

So what I understood is that you want to keep the latest 20 folders named by the date they were created. The remaining folders shall be deleted.

Code: Select all

@echo off &setlocal
for /f "skip=20 delims=" %%i in ('dir /ad /b /o-n^|findstr /x "20[0-9][0-9]-[01][0-9]-[0-3][0-9]"') do rd /s /q "%%i"


Steffen

Post Reply