得到当前目录下的所有文件名

[size=x-small][color=red]others:[/color][/size]
Dim Dtb As New DataTable
Dim myDataRow As DataRow
Dim myDataColumn As New DataColumn
myDataColumn.DataType = System.Type.GetType("System.String")
myDataColumn.ColumnName = "文件名"
Dtb.Columns.Add(myDataColumn)
Dim dirs As String() = Directory.GetFiles(Application.StartupPath, "*.dat")
MsgBox(Application.StartupPath)
For Each dir As String In dirs
myDataRow = Dtb.NewRow()
myDataRow.Item(0) = dir.Replace(Application.StartupPath & "\", "")'去掉路径,只显示文件名
Dtb.Rows.Add(myDataRow)
Next
DataGrid1.DataSource = Dtb
End Sub

[color=red]myself:[/color]
string[] dim=System.IO.Directory.GetFiles(Application.StartupPath,"*.xls");
string firstoldfilename=dim[0].ToString();
string oldfilename=dim[0].Replace(Application.StartupPath,"");
oldfilename=oldfilename.Replace("\\","");
string newoldfilename=oldfilename.Replace(".xls","");

你可能感兴趣的:(net)