Yes, you can get the dates and names of the files
previous 05 days previous date via bat/cmd:
Reads the date system and turn into numbers: 2019/01/01 = 20190101
That number subtraction the number of date - 05 days: 20190101-20181227=8874
We do the same with all months obtaining the days to be subtracted month by month
Dai filtering via for
looping whatever less/equal to 05 and greater/equal to 06
We used a loop for
(4 + 2020 to 2100), for compare if the current year is leap
Num array: Mês=_i Dias_Subtrair=_j
set _m_d=01-8874,02-75,03-!_f!..
As month-day variables compared with the position %%i-%%j
, gives how much subtract
Hence, if the day is less than 06, subtract the %%j
, but, subtract 1
Remarks:
Log file. will be servant in the briefcase %temp% and moved briefcase !_path_pdf!
Content of log file. will be copied to your Ctrl+c
Edit the command: Set "_path_pdf=."
Substituting the value: =.
for =drive:\pasta\onde\tem\os\pdfs
So that it stays: set "_path_pdf=drive:\pasta\onde\tem\os\pdfs"
Script -05_days.cmd:
@echo off && setlocal enableextensions enabledelayedexpansion
rem :: Edite variavel _path_pdf substituindo por drive/pasta/dos/seus/pdf's ::
cd /d "%~dp0" && set "_path_pdf=." && cd /d "!_path_pdf!"
rem :: Compondo string para uso com findstr onde verifica ano atual/bisexto ::
for /l %%l in (2020 4 2100)do set _b6to=!_b6to!%%l,
set "_do=wmic Path Win32_LocalTime Get Day^,Month^,Year"
rem :: Obtendo a data com layout previsível e sem possível customização do usurario ::
for /f "tokens=1-3delims= " %%a in ('!_do!^|findstr /r [0-9]')do (
set "_y=%%c" & set "_dd=0%%a" & set "_mm=0%%b" & set "_m=!_mm:~-2!"
set "_d=!_dd:~-2!" & set "_dt=!_y!_!_m!_!_d!" & set "_dt_str=!_y!!_m!!_d!"
) && set /a "_loop=1!_d!-101" & set "_cnt=0" & set "_log=%temp%\!_dt!.log"
rem :: Compondo um "pseudo" array para uso em alguns loopings for junto call :^[ ::
rem :: Observando que o 01 = mes c 2 digitos e o 8875, são os dias para subtrair ::
rem :: os dias/datas pregressas tratadas como mumeros. 20190105 -8875 = 20181231 ::
rem :: Procurando ano bisexto na string com findstr para verificar se ano bisexto ::
echo/!_b6to!|findstr /lic:"!_y!,">nul && set /a "_f=77" || set /a "_f=78"
set "_m_d=01-8874,02-75,03-!_f!,04-75,05-76,06-75,07-76,08-75,09-75,10-75,11-75,12-76"
rem :: Identificando mes/dias quantitativos para subtrair na data atual -05 dias ::
for %%~ in (!_m_d!)do for /f "tokens=1,2delims=-" %%i in ('echo/%%~')do (
if 1!_d! gtr 105 if /i [%%i] equ [!_m!] call :^] %%j "5 -1 1" 5 & goto :^)
if 1!_d! leq 105 if /i [%%i] equ [!_m!] call :^] %%j "1 +1 5" 1 & goto :^)
)
:^]
rem :: 1) Datas sendo subtraidas para obter intervalo de 05 dias anteriores a !_dt! ::
rem :: 2) Compondo layout/pattern do intervalo de datas e buscas dos Arquivos .PDFs ::
rem :: 3) Buscando e registrando resultados obtidos no Arquivo log %temp%\!_dt!.log ::
echo/Listagem do^(s^) Arquivo^(s^) Desatualizados em !_dt:_=/!:>"!_log!" && for /l %%l in (%~2)do (
if %%l leq !_loop! (set /a "_d[%%l]=!_dt_str!-%%l") else (set /a "_d[%%l]=!_dt_str!-%1" & set /a "_dt_str+=1")
set "_str_%%l=!_d[%%l]!" & call set "_str_%%l=*_!_str_%%l:~,4!_!_str_%%l:~4,2!_!_str_%%l:~-2!_*.pdf"
if /i exist ".\!_str_%%l!" where .:"!_str_%%l!">>!_log!
)
rem :: 4) Listando os resultados das acoes e portando dados p/ crtl+c/ctrl+v e tela ::
for /f "tokens=*delims=:" %%i in ('type "!_log!"^|find /c ".pdf"')do set "_cnt=%%i"
>> !_log! echo/Total de Arquivo^(s^) Desatualizado^(s^): !_cnt! && type "!_log!" | clip
>nul move /y "!_log!" . && exit /b
:^)
type ".\!_dt!.log" && endlocal & goto :eof
Upshot:
Using a bat that changes the date several times and testing the saturdays/days:
Administrator credential required
Obs.: The for
in the date format of my system, check yours by cmd: date <nul|find "("
If necessary change in (10-01-2018 12-05-2018 21-05-2018 05-01-2019 01-10-2019 05-12-2019)
changing to your system compliance.
@echo off && setlocal enableextensions enabledelayedexpansion
mode con cols=60 lines=15 & title SO_pt-BR_Q376119
rem :: data no formato yyyy-mm-dd, apenas altere para o layout de seu sistema:
for %%i in (10-01-2018 12-05-2018 21-05-2018 05-01-2019 01-10-2019 05-12-2019)do (
>nul date %%i
echo/Data em !date! & call :SO_pt-BR_Q376119
)
:SO_pt-BR_Q376119
@echo off && setlocal enableextensions enabledelayedexpansion
set "_pdf_folder=." && cd /d "!_pdf_folder!"
for /l %%l in (2020 4 2100)do set _b6to=!_b6to!%%l,
set "_do=wmic Path Win32_LocalTime Get Day^,Month^,Year"
for /f "tokens=1-3delims= " %%a in ('!_do!^|findstr /r [0-9]')do (
set "_y=%%c" & set "_dd=0%%a" & set "_mm=0%%b" & set "_m=!_mm:~-2!"
set "_d=!_dd:~-2!" & set "_dt=!_y!_!_m!_!_d!" & set "_dt_str=!_y!!_m!!_d!"
) && set /a "_loop=1!_d!-101" & set "_cnt=0" & set "_log=%temp%\!_dt!.log"
echo/!_b6to!|findstr /lic:"!_y!,">nul && set /a "_f=77" || set /a "_f=78"
set "_m_d=01-8874,02-75,03-!_f!,04-75,05-76,06-75,07-76,08-75,09-75,10-75,11-75,12-76"
for %%~ in (!_m_d!)do for /f "tokens=1,2delims=-" %%i in ('echo/%%~')do (
if 1!_d! gtr 105 if /i [%%i] equ [!_m!] call :^] %%j "5 -1 1" 5 & goto :^)
if 1!_d! leq 105 if /i [%%i] equ [!_m!] call :^] %%j "1 +1 5" 1 & goto :^))
:^]
echo/Listagem do^(s^) Arquivo^(s^) Desatualizados em !_dt:_=/!:>"!_log!" && for /l %%l in (%~2)do (
if %%l leq !_loop! (set /a "_d[%%l]=!_dt_str!-%%l") else (set /a "_d[%%l]=!_dt_str!-%1" & set /a "_dt_str+=1")
set "_str_%%l=!_d[%%l]!" & call set "_str_%%l=*_!_str_%%l:~,4!_!_str_%%l:~4,2!_!_str_%%l:~-2!_*.pdf"
if /i exist ".\!_str_%%l!" where .:"!_str_%%l!">>!_log!
)
for /f "tokens=*delims=:" %%i in ('type "!_log!"^|find /c ".pdf"')do set "_cnt=%%i"
>>!_log! echo/Total de Arquivo^(s^) Desatualizado^(s^): !_cnt! |clip & exit /b
:^)
type "!_log!" & timeout /t 7 >nul & cls & endlocal && exit/b
Upshot:
Update - For those interested in reward
Below a pdf file generator that obey the layout of the question.
Remarks:
To generate in previous years just change the date on the system to desired year
Generates files in mode .txt renamed p .pdf of 2019-01-01 until 2019-12-31
After generating the files it is possible to test the outputs of the posted answers.
Script gera_pdf.cmd:
@echo off && setlocal enableextensions enabledelayedexpansion
set "_do=wmic Path Win32_LocalTime Get Day^,Month^,Year" & for /l %%l in (2020 4 2100)do set "_leap=!_leap!%%l,"
for /f "tokens=1-3delims= " %%a in ('!_do!^|findstr /r [0-9]')do set "_y=%%c" & set "_dd=0%%a" & set "_mm=0%%b"
set "_m=!_mm:~-2!" && set "_d=!_dd:~-2!" && set "_dt=!_y!_!_m!_!_d!" && set /a "_l=!_mm:~1!-1" && set /a "_int=0"
echo/!_leap!|findstr /lic:"!_y!," >nul && (set /a _f=2, _fev=29, _ano=366) || (set /a _f=3, _fev=28, _ano=365)
set "_m_d=01-31,02-!_fev!,03-31,04-30,05-31,06-30,07-31,08-31,09-30,10-31,11-30,12-31" & set "_log=%temp%\!_dt!.log"
set "_i=-1" & set "_soma=# 0 !_f! 0 1 0 1 0 0 1 0 1 0" & call set "_soma=!_soma!" && set "_soma=%_soma: ="
set /a _i+=1&set "_soma!_i!=%" && set /a _soma=0, _alvo=0&& for /l %%S in (0 1 !_l!)do if not "%%S" == "!_l!" (set /a "_soma+=%%S") else set /a _cnt=%%S * 31 - !_soma!
call set /a "_alvo=!_cnt! + !_dd:~1! - 6" && set "_p=!_dd:~1!" & set /a "_cnt+=!_p!" & for %%I in (!_m_d!)do (
for /f "tokens=1,2delims=-" %%i in ('echo/%%I')do for /l %%x in (1 1 %%j)do set /a "_int+=1" & (
if %%x leq 9 (set "_x=%%i_0%%x" & set "_a=0%%x!_a!") else (set "_x=%%i_%%j" & set "_a=%%x!_a!")
call set _random=%random% && call echo/where .:*_!_y!_%%i_!_a:~0,2!_!_x:_=!.pdf >"!_random: =!_!_y!_%%i_!_a:~0,2!_%%i%%j.pdf"
))
)
- - -
Update: without comments and ported to files of any length, only and use the variable set _ext=pdf
, exchanging the value pdf
by the desired length, noting not to use "." in the variable.
@echo off && setlocal enableextensions enabledelayedexpansion
set "_ext=pdf" & set "_do=wmic Path Win32_LocalTime Get Day^,Month^,Year"
cd /d "%~dp0" && set "_path_pdf=." && cd /d "!_path_pdf!"
for /l %%l in (2020 4 2100)do set _b6to=!_b6to!%%l,
for /f "tokens=1-3delims= " %%a in ('!_do!^|findstr /r [0-9]')do (
set "_y=%%c" & set "_dd=0%%a" & set "_mm=0%%b" & set "_m=!_mm:~-2!"
set "_d=!_dd:~-2!" & set "_dt=!_y!_!_m!_!_d!" & set "_dt_str=!_y!!_m!!_d!"
) && set /a "_loop=1!_d!-101" & set "_cnt=0" & set "_log=%temp%\!_dt!.log"
echo/!_b6to!|findstr /lic:"!_y!,">nul && set /a "_f=77" || set /a "_f=78"
set "_m_d=01-8874,02-75,03-!_f!,04-75,05-76,06-75,07-76,08-75,09-75,10-75,11-75,12-76"
for %%~ in (!_m_d!)do for /f "tokens=1,2delims=-" %%i in ('echo/%%~')do (
if 1!_d! gtr 105 if /i [%%i] equ [!_m!] call :^] %%j "5 -1 1" 5 & goto :^)
if 1!_d! leq 105 if /i [%%i] equ [!_m!] call :^] %%j "1 +1 5" 1 & goto :^)
)
:^]
echo/Listagem do^(s^) Arquivo^(s^) Desatualizados em !_dt:_=/!:>"!_log!" && for /l %%l in (%~2)do (
if %%l leq !_loop! (set /a "_d[%%l]=!_dt_str!-%%l") else (set /a "_d[%%l]=!_dt_str!-%1" & set /a "_dt_str+=1")
set "_str_%%l=!_d[%%l]!" & call set "_str_%%l=*_!_str_%%l:~,4!_!_str_%%l:~4,2!_!_str_%%l:~-2!_*.!_ext!"
if /i exist ".\!_str_%%l!" where .:"!_str_%%l!">>!_log!
)
for /f "tokens=*delims=:" %%i in ('type "!_log!"^|find /c ".!_ext!"')do set "_cnt=%%i"
>> !_log! echo/Total de Arquivo^(s^) Desatualizado^(s^): !_cnt! && clip <"!_log!"
>nul move /y "!_log!" . & exit /b
:^)
type ".\!_dt!.log" && endlocal & goto :eof
good morning, yes has underline between(*filename)(year)(month)day(time) and at the time no dots or dashes or underline would be together!
– Walisson
show what you’ve done..., put an example of the line you want to treat, is much easier to understand than reading an explanation of the line format, and put an example of the log line you want to have
– zentrunix
Of course it is possible to do it in bat - but it is the kind of problem that is best solved in a higher-level language that has a better separation between data and command parameters. The same problem in Python, for example, would be solved by a program that would be much more readable and smaller. Probably in visual basic as well
– jsbueno
I don’t understand, everything is solved with high-level language, no doubt, why not delete :as tags: cmd/bat/batch/script/etc... Why are questions accepted and not closed? It is not the case to solve the problem, it is the case of thus solve the problem.
– It Wasn't Me
@jsbueno o o op specified .bat. If we start to choose the language and the system in which we will give the answers all questions will have to be closed because they are too broad or because they are subjective because for example I do not think that in Python if you get a good answer I believe that in PHP I get a higher response than Python. Then soon after will arise another op who will claim that in Java a higher response is achieved thus eliminating the need for tags.
– Augusto Vasques
I understand to have in bat a difficulty that is not recognized, personal uses the powershel, yes, it is easier, yes, it has infinite resources, yes, but ignore, do not recognize, the difficulty that is to respond using a command interpreter with its limitations.
– It Wasn't Me