1

I get the EXE files from a Polyspace-Config and then I want to rename them all with "result_" in front.

But something is wrong:

 @echo off

 FOR /f "tokens=*" %%G IN ('dir C:\PolyspaceProjects\*_exe* /b') DO (
    set filename = %%G
    set prefix = result_
    echo %prefix%%filename%
)

This solves it (must use ! instead of % when echoing the variable and need setlocal enabledelayedexpansion): %%F variable always referencing the last item in a FOR loop instead of the current one And this link explains things pretty well: https://ss64.com/nt/for_f.html

@echo off 
cls
setlocal enabledelayedexpansion

FOR /f "tokens=*" %%G IN ('dir C:\temp\*Gold* /b') DO (
  SET dog=%%G
  echo !dog!
  echo %%G
)

This is what I did for now... WORKS (would have liked to have used SET and variables for future modifications):

@echo off 
cls
setlocal enabledelayedexpansion

FOR /f "tokens=*" %%G IN ('dir C:\PolyspaceProjects\*_exe* /b') DO (
    rem Remove the file extension in the string
    for /f "tokens=1 delims=." %%A in ("%%G") do (
        echo polyspace-bug-finder -options-file c:\PolyspaceProjects\%%G -options-file "C:\PolyspaceProjects\BugFinderOptions.psops" -results-dir results_%%A
    )
)
jdl
  • 6,151
  • 19
  • 83
  • 132
  • 3
    A couple of things are going on here. You've got a combination of https://stackoverflow.com/questions/9681863/windows-batch-variables-wont-set and https://stackoverflow.com/questions/41591753/batch-delayed-expansion-not-working-as-expected – SomethingDark Jul 24 '20 at 00:09
  • 1
    And your third problem is that the the FOR variable is not expanding to the full path. So depending on what the current working directory is, this code will fail when it tries to rename a file. Regardless of that you could do this all in one line of code if you just don't bother with creating variables and just use the FOR variable. – Squashman Jul 24 '20 at 01:30

0 Answers0