Answer the question
In order to leave comments, you need to log in
Storage of files for 2 months + 1 file on the first day of the month?
Good day everyone! Friends, if it's not difficult, who knows... Task: there are a lot of backup files, you need to save 1 file for the 1st day of each month, as well as backups for the last 2 months for each day.
In fact, making storage for 2 months is as easy as shelling pears:
forfiles -p "C:\some_folder" -s -m *.* -d -60 -c "cmd /c del /q @path"
REM -- moving 1st of month folders to temp\
forfiles /M *_FULL_20*01_*.csv /C "cmd /c move @path temp\ "
REM -- deleting files older than 30 days
forfiles /M *_FULL_20*.csv /D -30 /C "cmd /c del /s /q @path "
REM -- bringing back temp\ to this folder
forfiles /P temp\ /C "cmd /c move @path ..\ "
forfiles -p "c:\folder" -s -m *.* -d -1 -c "cmd /c copy @path c:\folder\1st_dates"
forfiles -p "c:\folder" -s -m *.* -d -60 -c "cmd /c del /q @path"
Answer the question
In order to leave comments, you need to log in
You can call a pipeline in cmd, in which you can try to filter files for the first number.
Roughly something like this:
forfiles -p "c:\folder" -s -m *.* -d -1 -c "cmd /c (dir @path | findstr /v /r /c:"тут регулярное выражение для поиска 1 дня в дате") && del /q @path"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question