Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

How to? working with arrays

Apr
1,794
15
Code:
SETLOCAL

  setdos /x-1256789A

  if not isdir .\test\ md .\test\

  setarray /f info[10,1]

  set info[0,0]=CompanyName
  set info[1,0]=FileDescription
  set info[2,0]=FileVersion
  set info[3,0]=InternalName
  set info[4,0]=LegalCopyright
  set info[5,0]=LegalTrademarks
  set info[6,0]=OriginalFileName
  set info[7,0]=ProductName
  set info[8,0]=ProductVersion
  set info[9,0]=Build

  for %fn in (*.exe) gosub :doExe "%fn"
  goto :end

  :doEXE

    set sNew=
    rem build new EXE name
    For /l %n in (0,1,9) echo if "%@trim[%@verinfo[%fn,@info[%n]]]" NE "" set %sNew=%sNew-`%@trim[%@verinfo[%fn,@info[%n]]]`
    move /r /n "%fn" "test\%sNew"

:end

  setdos /x+1256789A
ENDLOCAL

QUIT
Code:

This code snippet isn't producing the expected results for the "For /l %n in" line. What am i doing wrong please?
 
This is fishy: set %sNew=%sNew .... I'm guessing you meant set sNew=%fn... (no % on the sNew).

And none of that will happen because it's only being ECHOed (not executed). So the next line (move) seems like nonsense.

And I don't see a RETURN in your subroutine.
 
This is fishy: set %sNew=%sNew .... I'm guessing you meant set sNew=%fn... (no % on the sNew).

And none of that will happen because it's only being ECHOed (not executed). So the next line (move) seems like nonsense.

And I don't see a RETURN in your subroutine.
Two other problems I see are in this part of the line: %@trim[%@verinfo[%fn,@info[%n]]]"

When you refer to the info variable you need a %, not an @. But when you correct that it still won't work as you've defined a two dimensional array but are refering to it as a one dimensional array, which will give you an Invalid array argument (out of bounds) error. I'm not sure why you've defined it as a two dimensional array, perhaps you need the second dimension in another part of your batch file as this is just a snippet, but you need to either change to a one dimensional array or change the reference in your problem line to %info[%n,0]. There are two such references in the problem line, you need to correct both of them.
 
This is fishy: set %sNew=%sNew .... I'm guessing you meant set sNew=%fn... (no % on the sNew).

And none of that will happen because it's only being ECHOed (not executed). So the next line (move) seems like nonsense.

And I don't see a RETURN in your subroutine.

Good morning. What I am trying to do with the for /l %n in (0,1,9) line is to, after starting with a empty var, add the value of each of the verinfo fields if they are not empty, to the end of the var.

added the RETURN.

Why i am ECHOing the test is to help me debug the loop.
 
Complete BTM is below....

Code:
SETLOCAL

  setdos /x-1256789A

  if not isdir .\test\ md .\test\

  setarray /f info[10,1]

  set info[0,0]=CompanyName
  set info[1,0]=FileDescription
  set info[2,0]=FileVersion
  set info[3,0]=InternalName
  set info[4,0]=LegalCopyright
  set info[5,0]=LegalTrademarks
  set info[6,0]=OriginalFileName
  set info[7,0]=ProductName
  set info[8,0]=ProductVersion
  set info[9,0]=Build

  for %fn in (*.exe) gosub :doExe "%fn"
  goto :end

  :doEXE

    set sNew=
    rem build new EXE name
    For /l %n in (0,1,9) echo if "%@trim[%@verinfo[%fn,%info[%n]]]" NE "" set sNew=%sNew-`%@trim[%@verinfo[%fn,%info[%n]]]`
    move /r /n "%fn" "test\%sNew"

    return

:end

  setdos /x+1256789A
ENDLOCAL

QUIT
 
For /l %n in (0,1,9) echo if "%@trim[%@verinfo[%fn,%info[%n]]]" NE "" set sNew=%sNew-`%@trim[%@verinfo[%fn,%info[%n]]]`
You made info a 2-dimensional array: setarray /f info[10,1]. Reference it with a pair of indices ... %info[%n,0].

Or just make it a 1-D array in the first place.

Code:
setarray /f info[10]
set info[0]=CompanyName
...
 
The [For /l %n in (0,1,9) ...] doesn't seem right?

Code:
if "Zoom Video Communications, Inc." NE "" set sNew=-`Zoom Video Communications, Inc.`
if "Zoom Meetings Installer" NE "" set sNew=-`Zoom Meetings Installer`
if "5.15.0" NE "" set sNew=-`5.15.0`
if "Zoom Meetings Installer" NE "" set sNew=-`Zoom Meetings Installer`
if "© Zoom Video Communications, Inc. All rights reserved." NE "" set sNew=-`© Zoom Video Communications, Inc. All rights reserved.`
if "" NE "" set sNew=-``
if "Zoom Meetings Installer" NE "" set sNew=-`Zoom Meetings Installer`
if "Zoom Meetings Installer" NE "" set sNew=-`Zoom Meetings Installer`
if "5.15.0" NE "" set sNew=-`5.15.0`
if "" NE "" set sNew=-``
C:\Users\csgal\Downloads\EXEs_BTMs\test\Zoom_Meetings_Installer_5.15.0_5.15.0.exe -> C:\Users\csgal\Downloads\EXEs_BTMs\test\test\Zoom_Meetings_Installer_5.15.0_5.15.0.exe
     1 file would be moved
 
That looks pretty good to me. Remember, you're only ECHOing the IF ... SET statement. The SET isn't executed and sNew remains unset.
 

Similar threads

Back
Top