mercredi 25 mai 2022

Batch script to download file with random numbers in filename

I need to make a batch script that can downloads a file with random names like this:

file_123456_2022-05-25.txt file_654321_2022-05-25.txt file_888888_2022-05-25.txt

file_159753_2022-05-26.txt file_357159_2022-05-26.txt file_147896_2022-05-26.txt

and so on...

I'm using batch file like this:

@echo off

    setlocal enableextensions disabledelayedexpansion

    for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a" 
    set "td.YY=%dt:~2,2%" 
    set "td.YYYY=%dt:~0,4%"
    set "td.MM=%dt:~4,2%"
    set "td.DD=%dt:~6,2%"

    rem Remove padding from date elements and increase day
    set /a "y=%td.YYYY%", "m=100%td.MM% %% 100", "d=(100%td.DD% %% 100)+1" 
    rem Calculate month length
    set /a "ml=30+((m+m/8) %% 2)" & if %m% equ 2 set /a "ml=ml-2+(3-y %% 4)/3-(99-y %% 100)/99+(399-y %% 400)/399"
    rem Adjust day / month / year for tomorrow date
    if %d% gtr %ml% set /a "d=1", "m=(m %% 12)+1", "y+=(%m%/12)"

    rem Pad date elements and set tomorrow variables
    set /a "m+=100", "d+=100"

    set "tm.YYYY=%y%"
    set "tm.YY=%y:~-2%"
    set "tm.MM=%m:~-2%"
    set "tm.DD=%d:~-2%"

    echo Today   : %td.YYYY%-%td.MM%-%td.DD%.txt
    echo Tomorrow: %tm.YYYY%-%tm.MM%-%tm.DD%.txt
 
echo download starting up

timeout 3
M:\Task-Scheduler\WGet\wget https://www.mywebserver.com/file_%td.YYYY%-%td.MM%-%td.DD%.txt

this code can download files with dynamic date but not with dynamic numbers! I need to download something like this: M:\Task-Scheduler\WGet\wget https://www.mywebserver.com/file_******_%td.YYYY%-%td.MM%-%td.DD%.txt

How can I solve this?

Tnx in advance




Aucun commentaire:

Enregistrer un commentaire