Passing variable to subroutine
Posted: 12 Jun 2016 16:19
Hi, this is part of my code:
========================================
setlocal EnableDelayedExpansion
for /F "tokens=*" %%A in (All_csv.txt) do (
dir /b "%%A"* > "%%A".txt
)
for /F "tokens=*" %%A in ("%%A") do (
call :Delete_Last_Line '%%A'
)
:Delete_Last_Line %%A
set LINES=0
for /f "delims==" %%I in ("%%A") do (
set /a LINES=LINES+1
)
echo Total Lines : %LINES%
echo.
:: n = 1 , last n line will ignore
set /a LINES=LINES-1
call :PrintFirstNLine > "%%A".csv.txt
exit /b
:PrintFirstNLine
set cur=0
for /f "delims==" %%I in ("%%A") do (
echo %%I
::echo !cur! : %%I
set /a cur=cur+1
if "!cur!"=="%LINES%" goto EOF
)
exit /b
:EOF
========================================
I have a file named All_csv.txt and it contains a list of too many text files in the same path.
The idea of my script is to read all the lines from All_csv.txt file, create a new text file with the same name each row has and adding .txt and after that, delete last line in each text file created in there.
In my script, at the time I called subroutine, the error I got, said that the system cant find the file %A
The first FOR works ok, but at the time script jumps to the second FOR, it looks that the subroutine Delete_Last_Line can't find the file created in the first FOR.
I've tried in different ways to pass a variable and I can't make it work.
If I use in all the script a file name instead of a variable, the script works fine
Please could you take a look and let me know what I did wrong in my code?
Thank you in advance.
========================================
setlocal EnableDelayedExpansion
for /F "tokens=*" %%A in (All_csv.txt) do (
dir /b "%%A"* > "%%A".txt
)
for /F "tokens=*" %%A in ("%%A") do (
call :Delete_Last_Line '%%A'
)
:Delete_Last_Line %%A
set LINES=0
for /f "delims==" %%I in ("%%A") do (
set /a LINES=LINES+1
)
echo Total Lines : %LINES%
echo.
:: n = 1 , last n line will ignore
set /a LINES=LINES-1
call :PrintFirstNLine > "%%A".csv.txt
exit /b
:PrintFirstNLine
set cur=0
for /f "delims==" %%I in ("%%A") do (
echo %%I
::echo !cur! : %%I
set /a cur=cur+1
if "!cur!"=="%LINES%" goto EOF
)
exit /b
:EOF
========================================
I have a file named All_csv.txt and it contains a list of too many text files in the same path.
The idea of my script is to read all the lines from All_csv.txt file, create a new text file with the same name each row has and adding .txt and after that, delete last line in each text file created in there.
In my script, at the time I called subroutine, the error I got, said that the system cant find the file %A
The first FOR works ok, but at the time script jumps to the second FOR, it looks that the subroutine Delete_Last_Line can't find the file created in the first FOR.
I've tried in different ways to pass a variable and I can't make it work.
If I use in all the script a file name instead of a variable, the script works fine
Please could you take a look and let me know what I did wrong in my code?
Thank you in advance.