0

Recently I tried to Make a Batch Code to Download Radio Archive in a Schedule, But there was some problems I'm interested to understand better I needed to get Yesterday date It was too complex to make it in cmd, I tried VB

  File:yester.vbs
  d=date()-1
  wscript.echo year(d)*10000+month(d)*100+day(d)

output would be 20190814 for today, It's the then I tried to use it in a bat file and add link to IDM

  CD /D "C:\Program Files (x86)\Internet Download Manager\"
  for /f %%a in ('cscript //nologo yester.vbs') do set yesterday=%%a
  set DT=%yesterday%
  set YY=%DT:~0,4%
  set MM=%DT:~4,2%
  set DD=%DT:~6,2%
  IDMan.exe /a /d rtmp://%YY%%MM%%DD% /f %YY%%MM%%DD%.FLV

Stiil the problem is the code only work when it's on the same folder as IDM and VB Code File or else the Yesterday variable would change to "Input" In order to fix this problem I must add this Code in Beggining of Batch file. But it work without a problem in command prompt

  Setlocal EnableDelayedExpansion

then the bat file will work on any path I'm not a proffasional, still interested to know more about rules of using script in batch files. Thanks

Compo
  • 36,585
  • 5
  • 27
  • 39
  • [something like this?](https://stackoverflow.com/questions/4094699/how-does-the-windows-command-interpreter-cmd-exe-parse-scripts) – Stephan Aug 15 '19 at 20:10

1 Answers1

1

Either create the vbs on the fly in the folder,
or better drop it completely in favor of PowerShell.

Why do you get a date in the proper format, then split it into parts and assemble it to the very same state again?

@Echo off
CD /D "C:\Program Files (x86)\Internet Download Manager\"
for /f "usebackq" %%a in(
   `powershell -nop -c "(Get-Date).AddDays(-1).ToString('yyyyMMdd'")`
) Do IDMan.exe /a /d rtmp://%%a /f "%%a.FLV"

Edit A variant splitting the date with dots into %%a.%%b.%%c

@Echo off
CD /D "C:\Program Files (x86)\Internet Download Manager\"
for /f "usebackq tokens=1-3 delims=." %%a in(
   `powershell -nop -c "(Get-Date).AddDays(-1).ToString('yyyy\.MM\.dd'")`
) Do IDMan.exe /a /d rtmp://%%a%%b%%c /f "%%a%%b%%c.FLV"
  • Thanks for you reply, It take a while for me to understand your code. but I'm gratful for that. It's Actually a mistake from the time I tried to get Date from "Date" function and turn it from yyyy/mm/dd to yyyymmdd I also need to Break it for file name to change it to yyyy.mm.dd Because I need differnt formats of same date – Digiraiter Aug 15 '19 at 21:43
  • See added variant, which allows separate handling of year, month, day. –  Aug 15 '19 at 21:56