Note that there are some explanatory texts on larger screens.

plurals
  1. POMS-DOS batch script: assignment operation
    primarykey
    data
    text
    <p>I am referring to below threat <a href="https://stackoverflow.com/questions/206114/dos-batch-files-how-to-read-a-file">Batch files: How to read a file?</a>. For retrieving the line by line from a text file. I am using the below script:</p> <pre><code>@echo off SETLOCAL DisableDelayedExpansion FOR /F "usebackq delims=" %%a in (`"findstr /n ^^ paths.txt"`) do ( set "var=%%a" SETLOCAL EnableDelayedExpansion set "var=!var:*:=!" echo !var! ENDLOCAL ) </code></pre> <p>Code is working fine! The values in <code>!var!</code> can not assign to any variable. :( I struct there, Please anyone help to read line by line and I wish to assign to some variable and want to manipulate that variable. Please help to solve this situation.</p> <p><strong>Update:</strong></p> <pre><code>@ECHO off CLS SET PROJ_DIR=D:\workspace\proj SET PROMO_DIR=D:\TEST SET SOURCE_CODE=\Source Code SETLOCAL DisableDelayedExpansion for /f %%a in (paths.txt) do ( SET "var=%%a" SETLOCAL EnableDelayedExpansion set "var=!var:*:=!" set FILE_PATH=!var://www.domain.com/path/dir=! SET FILE_PATH=!FILE_PATH:/=\! SET PROMO_FILE_PATH=!PROMO_DIR!!SOURCE_CODE!!FILE_PATH! FOR %%i IN ("!PROMO_FILE_PATH!") DO SET FOLDER_PATH=%%~dpi FOR %%i IN ("!PROMO_FILE_PATH!") DO SET FILE_NAME=%%~nxi IF EXIST "!FOLDER_PATH!" GOTO F3 MKDIR "!FOLDER_PATH!" :F3 IF NOT EXIST "!PROJ_DIR!!FILE_PATH!" GOTO F4 COPY "!PROJ_DIR!!FILE_PATH!" "!FOLDER_PATH!" :F4 ECHO Cannot find the file under "!PROJ_DIR!!FILE_PATH!" ENDLOCAL ) SET CLOSE_CONFIRM= SET /P CLOSE_CONFIRM=Press any key to close the window...%=% </code></pre> <p><strong>paths.txt</strong></p> <pre><code>//www.domain.com/path/dir/dir1/dir2/file1.txt //www.domain.com/path/dir/dir1/dir2/file2.txt //www.domain.com/path/dir/dir1/dir2/file3.txt //www.domain.com/path/dir/dir1/dir2/file4.txt //www.domain.com/path/dir/dir1/dir3/file1.txt </code></pre> <p><strong>Command Output</strong></p> <pre><code> 1 file(s) copied. Cannot find the file under "D:\workspace\proj\dir1\dir2\file1.txt" 1 file(s) copied. Cannot find the file under "D:\workspace\proj\dir1\dir2\file2.txt" Press any key to close the window... </code></pre> <p>thanks..</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload