簡體   English   中英

循環中批量填充數組

[英]Batch populating array in loop

嗨,我有一個大問題,批處理很復雜,但是我想出了解決的方法,問題是我不知道如何批量處理,如果在C#中我可以輕松完成,因為我是新手批處理中,下面是c#,你們可以教我如何完全按照批處理方式進行嗎? 我會整天用谷歌搜索,但找不到辦法,謝謝

ArrayList list = new ArrayList();
//let say variable "Filesx" consist of files count in one folder

for(int i = 0; i < Filesx; i++){
   list.Add("file number : " + i);
}

P / S:如果無法批量使用arraylist,則單獨使用陣列就可以了

@echo off
setlocal EnableDelayedExpansion

rem Populate the array with existent files in folder
set i=0
for %%a in (*.*) do (
   set /A i+=1
   set list[!i!]=%%a
)
set Filesx=%i%

rem Display array elements
for /L %%i in (1,1,%Filesx%) do echo file number %%i: "!list[%%i]!"

您必須注意,為方便起見,批處理數組中的下標應從1開始,而不是0。

有關批處理文件中陣列管理的進一步說明,請參閱: cmd.exe(批處理)腳本中的陣列,鏈接列表和其他數據結構

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM