0
目錄和出口在DGV有我的代碼:我如何循環文件在VB.NET
For i As Integer = 0 To lstDir.Items.Count - 1
For Each File As String In Directory.GetFiles(lstDir.Items(i))
Fname = File.ToString.Substring(File.LastIndexOf("\") + 1)
i = +1
If File.Contains(".zip") Then
res = ""
For Each Str As Char In Fname
If IsNumeric(Str) Then
res = res & Str
End If
Next
For x As Integer = 0 To lstDir.Items.Count - 1
For Each newFile As String In Directory.GetFiles(lstDir.Items(x))
If newFile.Contains(res) Then
dgContents.Rows.Add(Fname)
End If
Next
Next
End If
Next
Next
想我的目錄包含以下文件:
abc123.pdf
def456.zip
ghi123.zip
jkl123.xml
mno456.pdf
pqr456.xml
,我需要選擇剛纔的所有.zip文件,獲取zip文件名中的數字,然後再次循環目錄,以從zip中搜索具有相同編號的文件,然後將其添加到datagrid。我的問題是,我的代碼顯示輸出是這樣的:的
def456.zip
def456.zip
def456.zip
ghi123.zip
ghi123.zip
ghi123.zip
代替
def456.zip
mno456.pdf
pqr456.xml
ghi123.zip
abc123.pdf
jkl123.xml
請幫助...