Forums before death by AOL, social media and spammers... "We can't have nice things"
|    alt.msdos.batch    |    Fun with MS-DOS batch files    |    42,547 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 41,926 of 42,547    |
|    Herbert Kleebauer to Ammammata    |
|    Re: delete files except the latest of ev    |
|    11 Feb 21 11:57:24    |
   
   From: klee@unibwm.de   
      
   On 10.02.2021 12:35, Ammammata wrote:   
   > there's a backup scheduled daily for many different files   
   >   
   > the related filenames are unique, i.e.   
   >   
   > RSP_backup_2021_02_09_200005_8336305.bak   
   > RSP_backup_2021_02_08_200007_8776502.bak   
   > RSP_backup_2021_02_07_200005_8652391.bak   
   > RSP_backup_2021_02_06_200005_4658428.bak   
   > RSP_backup_2021_02_05_200005_1944601.bak   
   > RSP_backup_2021_02_04_200005_6798320.bak   
   > RSP_backup_2021_02_03_200005_4282408.bak   
   > RSP_backup_2021_02_02_200005_0172624.bak   
   > RSP_backup_2021_02_01_200005_9353583.bak   
   > RSP_backup_2021_01_31_200006_2371866.bak   
   > RSP_backup_2020_12_31_200003_2429004.bak   
   > RSP_backup_2020_10_24_200004_0066296.bak   
   >   
   > I'd like to delete, about every 3-4 months, all the backups except the   
   > lates of every single month, tipically those with date 31/10/20 30/11/20   
   > 31/12/20 31/01/21 etc   
   >   
   > in the above list you can see I kept current month (feb) and left the   
   > latest of each previous one (jan, dec, oct)   
   >   
   > I do this manually, right now it's not a huge tast, using a file manager,   
   > but I wonder whether there is an automated solution since the different   
   > backups will grow   
      
   If the names are exactly as given above, this should work (remove 'echo'   
   before 'del' if the output is ok to actual delete the files):   
      
   @echo off   
   for %%i in (01 02 03 04 05 06 07 08 09 10 11 12) do (   
   for /f "skip=1" %%j in ('dir /b o-n RSP_backup_202?_%%i_??_?????   
   _???????.bak') do echo del %%j) 2>nul   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca