0

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
  • 1
    [Variables are not behaving as expected](https://stackoverflow.com/questions/30282784/variables-are-not-behaving-as-expected) – Magoo Jan 12 '23 at 16:22
  • @Compo I can't do that, I need the quotation marks. – One Defauter Jan 12 '23 at 19:48
  • I'm not sure why you are using the `FOR /L` loop at all! If you already have a variable named `all_fill`, which expands to a list of doublequoted filenpaths, why can you not use that instead? e.g. ```For /F %%G In (%all_fill%) Do Copy /Y %%G temp2```. – Compo Jan 13 '23 at 01:06
  • `set iffff=%Fill!COUNT!%` cannot work due to immediate `%`-expansion. A possible fix is `for %%Q in (!COUNT!) do set "iffff=!Fill%%Q!`; it's very important that the inner variable (`COUNT`) becomes expanded *before* the outer one… – aschipfl Jan 13 '23 at 12:07
  • @Compo I put the `FOR /L` to avoid a problem that can happen with the `all_fill` variable which is the character limit, it can be kind of hard to beat the limit, but I wanted to avoid it. Also I was using the `all_fill` variable to test the behavior of mogrify and convert, you may notice that the `all_fill` variable is not used anywhere else. Ahh, and thanks for commenting. – One Defauter Jan 14 '23 at 16:02
  • @aschipfl Oh, thanks for commenting. I did it a little differently based on what you said and it worked. It will make me avoid using the brackets `[]`. Thank you. – One Defauter Jan 14 '23 at 16:06

1 Answers1

0

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.

  • 1
    You can review the details of this _array management_ at [this answer](https://stackoverflow.com/questions/10166386/arrays-linked-lists-and-other-data-structures-in-cmd-exe-batch-script/10167990#10167990) – Aacini Jan 13 '23 at 04:52
  • @Aacini Thank you for sharing this [link](https://stackoverflow.com/questions/10166386/arrays-linked-lists-and-other-data-structures-in-cmd-exe-batch-script/10167990#10167990). It helped me understand a little bit more how I can use the `set` with brackets `[]` and other valid characters. – One Defauter Jan 14 '23 at 16:12