當我把這段代碼轉換,從VB:這段代碼轉換,從VB到C#
Dim r As DialogResult = FldSource.ShowDialog()
If r = Windows.Forms.DialogResult.OK Then
lstPath.Items.Clear()
lblSoLuong.Text = lstPath.Items.Count
txtPath.Text = FldSource.SelectedPath
Dim tenfile, FS() As FileInfo
Dim di As New DirectoryInfo(txtPath.Text)
FS = di.GetFiles("*.txt")
For Each tenfile In FS
lstPath.Items.Add(tenfile.FullName)
Next
lblSoLuong.Text = lstPath.Items.Count
End If
到C#:
try
FolderBrowserDialog FldSource = new FolderBrowserDialog();
DialogResult r = FldSource.ShowDialog();
if (r == DialogResult.OK)
lst_Path.Items.Clear();
lbl_Soluong.Text = lst_Path.Items.Count.ToString();
txt_Path.Text = FldSource.SelectedPath;
FileInfo tenfile, FS();
DirectoryInfo di = new DirectoryInfo(txt_Path.Text);
FS= di.GetFiles(".txt");
我在這一行有錯誤:
FS= di.GetFiles(".txt");
我想知道我的錯誤在哪裏?
也許你可以與我們的錯誤共享你收到? – David
需要*獲取文件 – Ric
您是否錯過了FS = di.GetFiles(「.txt」)中的「*」; ? –