简体   繁体   中英

Windows Shell Script: Can't make string substitution working in subroutine

Greetings dear Experts!

Could you please advice me on how to cope with the problem:

@echo off
cls

setlocal enabledelayedexpansion

path=%CD%;%path% 

set NumberOfPages=553
rem set /A MaxFileIndex=%Counter% - 1
set MaxFileIndex=1

del Output.txt

for /l %%i in (0,1,%MaxFileIndex%) do call :GenerateFileList %%i
goto :eof


::::::::::::::::::::::::::
:GenerateFileList
::::::::::::::::::::::::::
setlocal enabledelayedexpansion

set CurrentFileName="File(%1).txt"
echo !CurrentFileName:"=! > Output.txt
goto :eof

::::::::::::::::::::::::::
:eof
::::::::::::::::::::::::::
endlocal

This code echoes on the screen instead of writing to "ExtractedLinks.txt". What is the problem here?

I assume you mean Output.txt not ExtractedLinks.txt:

set c=!CurrentFileName:"=!
echo %c% > Output.txt

Also, unless you are doing something else in the for loop, you probably want to append instead of overwriting:

echo %c% >> Output.txt

And if you really want the filename to be ExtractedLinks.txt just change it.

echo %c% >> ExtractedLinks.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM