2015年1月27日 星期二

Batch file name string concatenation




Inside your for loop you show the value of %attachment%, so that value is NOT updated in each iteration; you must use delayed expansion to do so.
The set of values in for command is: (%directory% *.xml) that is, the value C:\temp and all files with .xml extension, that I assumed is none in current directory. After that, you use this value in %a% %directory%\%%n expression, so the result is -a C:\temp\C:\temp. I think there is not a point here.
If you want not the folder value in the list, just don't insert it and use %~NXn modifier in the forreplaceable parameter.
Below is the correct code:
copy *.xml C:\FTP
setLocal Enabledelayedexpansion
set "directory=C:\temp"
set "attachment= "
set "a= -a "
for %%n in ("%directory%\*.xml") DO ( 
set "attachment=!attachment! %a% %%~NXn "
echo.!attachment!
)
setlocal disabledelayedexpansion
echo.%attachment%

My Version
setLocal Enabledelayedexpansion
set "directory=E:\data_temp\~Ricky\testscript"
set "attachment= "
set "a= "
for %%n in ("%directory%\*.pcap") DO ( 
set "attachment=!attachment!%a%%%~NXn "
echo.!attachment!
)
setlocal disabledelayedexpansion
echo.%attachment%

PAUSE

沒有留言:

張貼留言

2023 Promox on Morefine N6000 16GB 512GB

2023 Promox on Morefine N6000 16GB 512GB Software Etcher 100MB (not but can be rufus-4.3.exe 1.4MB) Proxmox VE 7.4 ISO Installer (1st ISO re...