Windows批处理文件-在此变量中定义变量时出现问题变量+延迟变量

hmae6n7t  于 2023-01-14  发布在  Windows
关注(0)|答案(1)|浏览(135)

我在一个变量的循环部分遇到了一个问题。我想我应该像这样写它,它会工作:

set iffff=%Fill!COUNT!%

我将张贴整个代码,以获得更好的理解.

@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

所选文件的复制部分的输出始终如下所示:

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

daupos2t1#

我得到了它的帮助,从这个link的@Magoo标记,我只需要改变两件事。
这一点:

::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"
)

为此:

::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"
)

还有这个

::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!
)

为此:

::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
)

谢谢你的帮助。

相关问题