Home > Software engineering >  Windows Batch File - problem defining a variable within this variable a variable delayed variable
Windows Batch File - problem defining a variable within this variable a variable delayed variable

Time:01-15

I am having a problem in a loop part with a variable. I thought I would just put it like this and it would work:

set iffff=%Fill!COUNT!%

I will post the entire code to get a better understanding.

@echo off
setlocal EnableDelayedExpansion

::Program that opens a window to select the images/files
"%TEMP%\wxFileDialog.exe" "Todos os arquivos (*.*)|*.*" c:\ Open -m >TESTETSTETSET

::Directories are organized for each variable
set "Count=1"
FOR /f "tokens=1* delims=" %%A in ('type TESTETSTETSET') do (
    set Fill!Count!="%%A"
    set /a "Count =1"
)

::All variables with the directories are stored in a single variable
set "all_fill=%Fill1% %Fill2% %Fill3% %Fill4% %Fill5% %Fill6% %Fill7% %Fill8% %Fill9% %Fill10% %Fill11% %Fill12% %Fill13% %Fill14% %Fill15% %Fill16% %Fill17% %Fill18% %Fill19% %Fill20% %Fill21% %Fill22% %Fill23% %Fill24% %Fill25% %Fill26% %Fill27% %Fill28% %Fill29% %Fill30% %Fill31% %Fill32% %Fill33% %Fill34% %Fill35% %Fill36% %Fill37% %Fill38% %Fill39% %Fill40%"
set "all_fill=%all_fill:   =%"

::Gets the path of the first variable by removing only the file
for %%I in (%Fill1%) do set "otu1=%%~dpI"

::Cria uma pasta para separar os arquivos
mkdir "%otu1%temp2" >nul & cls

::Enters the path to what was taken from the first variable 
cd /d "%otu1%"

::Here you should copy all the selected files into the folder that has been created
set "COUNT=0"
for /l %%I in (1,1,100) do (
    set /a COUNT=!COUNT!   1
    set ifff=%Fill!COUNT!%
    copy "%ifff%" "%otu1%temp2"
    echo:!COUNT!
)


::Enters the folder that was created
cd /d "%otu1%temp2"
dir /d
pause
::Here it converts to a white image with the same name and then replaces the source file with this white image and the created folder is removed
convert * -fill white -colorize 100 -set filename:f %%t %%[filename:f].png
MOVE /Y * .\..
cd ..
rd temp2

The output of the copying part of the selected files is always something like this:

F:\testNew Folder>(
set /a COUNT=!COUNT!   1
 set ifff=
 copy "" "F:\newfolder\temp2"
 echo:!COUNT!
)
The system cannot find the specified path.
100

CodePudding user response:

I got it with help from this link that @Magoo marked, I only needed to change two things.

This:

::Directories are organized for each variable
set "Count=1"
FOR /f "tokens=1* delims=" %%A in ('type TESTETSTETSET') do (
    set Fill!Count!="%%A"
    set /a "Count =1"
)

For that:

::Directories are organized for each variable
set "Count=1"
FOR /f "tokens=1* delims=" %%A in ('type TESTETSTETSET') do (
    set Fill[!Count!]="%%A"
    set /a "Count =1"
)

And this:

::Here you should copy all the selected files into the folder that has been created
set "COUNT=0"
for /l %%I in (1,1,100) do (
    set /a COUNT=!COUNT!   1
    set ifff=%Fill!COUNT!%
    copy "%ifff%" "%otu1%temp2"
    echo:!COUNT!
)

For that:

::Here you should copy all the selected files into the folder that has been created
FOR /L %%I IN (1 1 100) DO (
    copy !Fill[%%I]! "%otu1%temp2" >nul & cls
)

Thank you for your help.

  • Related