Announcement

Collapse
No announcement yet.

Batch Programming

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Computer Chat Batch Programming

    Could anybody explain me why this batch script for DoS under WinXP is not working and variable n dosn't get correct values.
    Code:
    set y=
    set n=
    set m=
            for /L %%y in (2007,1,2008) do ( 
                echo year %%y            
                for /L %%m in (1,1,2) do ( 
                    set /A "n = %%m + 1" 
                    echo thismonth %%m nextmonth %%n
                        ) 
            )
    Could you just save it as some.bat on your system and test it?
    http://viparmenia.net/
    http://viparmenia.co/
    http://viparmenia.com/

  • #2
    Not really the forum for this. You should probably visit a site dedicated to Windows Scripting Host. Personally, I'd just rewrite the whole thing in Javascript.
    Translations provided by Google.

    Wayne Luke
    The Rabid Badger - a vBulletin Cloud demonstration site.
    vBulletin 5 API

    Comment


    • #3
      The main idea is to generate backup zip files from attachments of vbforum but for each month a separate zips. Full batch file must look like
      set y=
      set m=
      set n=

      for /L %%y in (2007,1,2010) do (
      echo year %%y
      for /L %%m in (1,1,2) do (
      set /A n = %%m + 1
      zip -urt %%y-%%m-01 -tt %%y-%n%-01 attachments-%%m-%%y.zip ..\attachments
      echo nextmonth %n%
      echo month %%m year %%y
      )
      )
      Sure the dos batch is not the best way to do this, but I just need it for a moment and it makes me really crazy, as of I can't understand why the variable n didn't get his value inside the batch file but when one checks the environment the value is correctly seted there.

      Personally I prefer linux shell script. Below the one that works for me long time. Running it time to time one gets not only separate zip files, but they are being updated, if any of attachment in corresponding month is changed. If somebody want to test, adapt the pathtoattach variable to path where your attachments are stored and chech the starting year.

      #!/bin/sh
      #set -x

      curyear=`date '+%Y'`
      curmnth=`date '+%m'`
      pathtoattach= /var/www/attachments/

      for (( year = 2007 ; year <= $curyear; year++ ))
      do
      for (( month = 1 ; month <= 12; month++ ))
      do
      arxfile=attachments-$month-$year.zip

      if [ -e $arxfile ]; then update='-u'; fi

      if [ $month -gt $curmnth -a $year -ge $curyear ]; then
      exit 0
      else
      if [ $month -eq $curmnth -a $year -eq $curyear ]; then
      echo "update of attachments for last month $month of year $year"
      zip $update -rt $year-$month-01 $arxfile $pathtoattach
      else
      upmonth=`expr $month + 1`
      upyear=$year

      if [ $month -eq 12 ]; then
      upyear=`expr $year + 1`
      upmonth=01
      fi

      echo "update of attachments from month $month to $upmonth of year $year"
      zip $update -rt $year-$month-01 -tt $upyear-$upmonth-01 $arxfile $pathtoattach
      fi
      fi
      done
      done
      http://viparmenia.net/
      http://viparmenia.co/
      http://viparmenia.com/

      Comment


      • #4
        I got it.
        There is a setting
        SetLocal EnableDelayedExpansion
        That must be used and additional variable inside the loop must be used then in "!" to get their current value inside the loop and not form globalenvironment.

        The preliminary script must be
        echo OFF
        SetLocal EnableDelayedExpansion
        for /L %%y in (2007,1,2010) do (
        echo year %%y
        for /L %%m in (1,1,12) do (
        set /A n = %%m + 1
        echo thismonth %%m nextmonth !n! year %%y
        zip -vurt %%y-%%m-01 -tt %%y-!n!-01 attachments-%%m-%%y.zip ..\attachments
        )
        )
        http://viparmenia.net/
        http://viparmenia.co/
        http://viparmenia.com/

        Comment

        widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
        Working...
        X