
<script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
getfilenames的問題求助!
現在能夠實作單個檔案路徑和檔案名的提取,實作方法如下:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OpenFileDialog1.ShowDialog()
Dim path As String = OpenFileDialog1.FileName
ListBox1.Items.Add(System.IO.Path.GetFullPath(path))
ListBox2.Items.Add(System.IO.Path.GetFileNameWithoutExtension(path))
End Sub
可是如果我要想用在openfiledialog中選擇多個檔案後,如何在listbox1和listbox2中分别顯示這多個檔案的路徑和檔案名呢?
請予以幫助,多謝!
__________________________________________________________________________
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
String[] files = openFileDialog1.FileNames;
foreach (string str in files)
{
ListBox1.Items.Add(str);
}
}
__________________________________________________________________________
OpenFileDialog1.Multiselect = True
OpenFileDialog1.Filter = "所有檔案(*.*)|*.* "
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim i As Int32 = OpenFileDialog1.FileNames.Length
Dim path() As String = OpenFileDialog1.FileNames //定義string數組
Dim x As Int32 = 0
For x = 0 To i - 1 //循環周遊
path(x) = OpenFileDialog1.FileNames(x) //擷取檔案名
ListBox1.Items.Add(path(x)) //加到listbox
ListBox2.Items.Add(path(x).Substring(path(x).LastIndexOf( "/ "))) //取子位元組
Next
End If
__________________________________________________________________________
傳回的是string[]周遊就行
__________________________________________________________________________
感謝大家的熱心回複,我用kaozhulanmao的方法實作了,是以分數給了kaozhulanmao,同時感謝ak-47和八戒。
__________________________________________________________________________
直接用這個軟體http://essentialsoft.cn/copyfilenames
__________________________________________________________________________