none
How to code this batchfile? RRS feed

  • Question

  • I would like to know on how to add current year into following URL using batch file as shown below

    For 2018, www.ABC2018.com

    For 2019, www.ABC2019.com

    Does anyone have any suggestions?
    Thanks in advance for any suggestions


    Thanks in advance for any suggestions


    Monday, July 9, 2018 3:09 AM

Answers

  • you will haveto chain the start command like this:

    for /f "skip=1" %%y in ('wmic path win32_localtime get year') do @echo %%y | find /v "ECHO" >nul && start /b /max "IE" "C:\Program Files\Internet Explorer\iexplore.exe" "http://www.ABC%%y.com"

    • Marked as answer by oemMicrosoft Monday, July 9, 2018 12:30 PM
    Monday, July 9, 2018 11:34 AM

All replies

  • Just copy them into a file using notepad.

    What is it you are trying to do? Are you trying to run IE?  You can just create a shortcut to open IE to a specific web site.


    \_(ツ)_/

    Monday, July 9, 2018 3:39 AM
  • I would like to use code to insert year 2018 / 2019 into URL.

    www.ABC2018.com, so 2018 is generated by coding instead of hard code.

    "www.ABC" & Code insert here to display 2018 & ".com"

    Do you have any suggestions how to code it?
    Thank you very much for any suggestions (^v^)


    Thanks in advance for any suggestions

    Monday, July 9, 2018 3:53 AM
  • echo www.ABC%year%.com

    \_(ツ)_/

    Monday, July 9, 2018 3:56 AM
  • Your coding still show up www.ABC%year%.com instead of www.ABC2018.com.

    Do you have any suggestions on what wrong it is?
    Thank you very much for any suggestions (^v^)


    Thanks in advance for any suggestions

    Monday, July 9, 2018 4:15 AM
  • Don't you think you should learn a bit about Windows and batch files before asking a question.  What year are yu looking for?  THis year? Last year? Next year? You birth year?

    Where are you going to get the year from?


    \_(ツ)_/

    Monday, July 9, 2018 4:17 AM
  • Code should generate current year and return results as shown below?

    www.ABC2018.com, but coding %year% still show up %year% instead of 2018

    Do you have any suggestions?
    Thank you very much for any suggestions (^v^)


    Thanks in advance for any suggestions


    Monday, July 9, 2018 5:24 AM
  • Start by learning PowerShell.  CMD is obsolete and will not  be available in future versions of Windows.

    type the following.

    set /?

    In PowerShell

    "www.ABC$([datetime]::Today.Year).com"

    In batch:

    set year=2018
    echo "www.ABC%year%.com"


    \_(ツ)_/


    • Edited by jrv Monday, July 9, 2018 5:41 AM
    • Proposed as answer by BOfH-666 Monday, July 9, 2018 6:21 AM
    Monday, July 9, 2018 5:40 AM
  • This works if the short date format of your chosen language ends with yyyy.

    echo www.ABC%DATE:~-4%.com

    Monday, July 9, 2018 7:26 AM
  • For batchfile, coding look like as shown below, I would like to know on what coding look like in powershell.
    start /b /max "IE" "C:\Program Files\Internet Explorer\iexplore.exe" "http://www.ABC2018.com"

    Do you have any suggestions?
    Thanks, to everyone very much for any suggestions (^v^)

    Thanks in advance for any suggestions

    Monday, July 9, 2018 8:50 AM
  • This works if the short date format of your chosen language ends with yyyy.

    echo www.ABC%DATE:~-4%.com

    For batchfile, would it be possible to show yyyy format (2018)?

    Do you have any suggestions?
    Thanks, to everyone very much for any suggestions (^v^)


    Thanks in advance for any suggestions

    Monday, July 9, 2018 9:36 AM
  • This will also work in a Batch file.

    for /f "skip=1" %%y in ('wmic path win32_localtime get year') do @echo %%y | find /v "ECHO" >nul && start /b /max "IE" "C:\Program Files\Internet Explorer\iexplore.exe" "http://www.ABC%%y.com"

    • Edited by I-MANjuel Monday, July 9, 2018 11:30 AM
    Monday, July 9, 2018 11:09 AM
  • Yes, it works perfect, but when I insert those code into following coding, the coding format seems not working.

    [Not working] start /b /max "IE" "C:\Program Files\Internet Explorer\iexplore.exe"  for /f "skip=1" %y in ('wmic path win32_localtime get year') do @echo %y | find /v "ECHO" >nul && echo www.ABC%y.com

    [Working] start /b /max "IE" "C:\Program Files\Internet Explorer\iexplore.exe" "http://www.ABC2018.com"

    Do you have any suggestions on what wrong it is ?
    Thanks, to everyone very much for any suggestions (^v^)


    Thanks in advance for any suggestions

    Monday, July 9, 2018 11:28 AM
  • you will haveto chain the start command like this:

    for /f "skip=1" %%y in ('wmic path win32_localtime get year') do @echo %%y | find /v "ECHO" >nul && start /b /max "IE" "C:\Program Files\Internet Explorer\iexplore.exe" "http://www.ABC%%y.com"

    • Marked as answer by oemMicrosoft Monday, July 9, 2018 12:30 PM
    Monday, July 9, 2018 11:34 AM
  • Your given code work only if I paste it on cmd, but when I save those code into batch file, and run batch file, IE does not open at all.

    Do you have any suggestions on what wrong it is?
    Thanks, to everyone very much for any suggestions (^v^)


    Thanks in advance for any suggestions


    Monday, July 9, 2018 11:53 AM
  • The only thing i can think of is that you use single percentage (%y). This will work in a console but not in a batch file.

    Inside a batch, a for-command variable haveto be written with dual percentage %%y

    Monday, July 9, 2018 12:13 PM
  • It works perfert :>Thanks, to everyone very much for suggestions (^v^)

    Thanks in advance for any suggestions

    Monday, July 9, 2018 12:31 PM