function Newfile as fileinfo
創(chuàng)新互聯(lián)公司專注于興業(yè)網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供興業(yè)營銷型網(wǎng)站建設(shè),興業(yè)網(wǎng)站制作、興業(yè)網(wǎng)頁設(shè)計、興業(yè)網(wǎng)站官網(wǎng)定制、小程序開發(fā)服務(wù),打造興業(yè)網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供興業(yè)網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。
Dim dic As New System.IO.DirectoryInfo("C:\Users\Q\Desktop\數(shù)據(jù)")
Dim files = dic.GetFiles.OrderByDescending(Function(s) s.CreationTime)
if files.
return files.first
end function
注意引入 system.linq
先用System.IO.Directory.GetDirectories函數(shù)獲取子目錄的名稱(包括其路徑),再用System.IO.Path.GetFileName獲取子目錄的名稱。下面是代碼:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
For Each s In System.IO.Directory.GetDirectories("C:\Windows")
Console.WriteLine(System.IO.Path.GetFileName(s))
Next
End Sub
下面是部分輸出:
Application Data
AppPatch
assembly
BOCNET
Boot
Branding
ConfigSetRoot
Cursors
Debug
DigitalLocker
Downloaded Installations
Downloaded Program Files
ehome
en-US
Fonts
Globalization
Help
...
可能有更簡潔的方法,你可以到MSDN看看
System.IO.Directory.GetDirectories:
System.IO.Path.GetFileName:
通用 I/O 任務(wù):
Dim dDirectory As System.IO.Directory
Dim sName() As String
sName = dDirectory.GetFiles(path)
Dim dialog As OpenFileDialog = New OpenFileDialog
If dialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
Dim filename As String
filename = dialog.FileName
Dim results() As String
results = filename.Split("\")
filename = results(results.Length - 1)
filename = filename.Substring(0, filename.LastIndexOf("."))
MessageBox.Show(filename)
End If
dialog.Dispose()
獲取方法,參考實例如下:
'獲取路徑名各部分: 如: c:\dir1001\aaa.txt
'獲取路徑路徑 c:\dir1001\
Public Function GetFileName(FilePathFileName As String) As String '獲取文件名 aaa.txt
On Error Resume Next
Dim i As Integer, J As Integer
i Len(FilePathFileName)
J InStrRev(FilePathFileName, "\")
GetFileName Mid(FilePathFileName, J + 1, i)
End Function
''獲取路徑路徑 c:\dir1001\
Public Function GetFilePath(FilePathFileName As String) As String '獲取路徑路徑 c:\dir1001\
On Error Resume Next
Dim J As Integer
J InStrRev(FilePathFileName, "\")
GetFilePath Mid(FilePathFileName, 1, J)
End Function
'獲取文件名但不包括擴展名 aaa
Public Function GetFileNameNoExt(FilePathFileName As String) As String '獲取文件名但不包括擴展名 aaa
On Error Resume Next
Dim i As Integer, J As Integer, k As Integer
i Len(FilePathFileName)
J InStrRev(FilePathFileName, "\")
k InStrRev(FilePathFileName, ".")
If k 0 Then
GetFileNameNoExt Mid(FilePathFileName, J + 1, i - J)
Else
GetFileNameNoExt Mid(FilePathFileName, J + 1, k - J - 1)
End If
End Function
'===== '獲取擴展名 .txt
Public Function GetFileExtName(FilePathFileName As String) As String '獲取擴展名 .txt
On Error Resume Next
Dim i As Integer, J As Integer
i Len(FilePathFileName)
J InStrRev(FilePathFileName, ".")
If J 0 Then
GetFileExtName ".txt"
Else
GetFileExtName Mid(FilePathFileName, J, i)
End If
End Function
使用DOS命令就可以完成:DIR D:\文件\ * TXT / S / / B D:\ 1.txt文件。使所有的TXT集成到1.txt文件的文件名。
文章標(biāo)題:vb.net取文件名稱,vb生成文件夾
本文來源:http://aaarwkj.com/article14/dsigsge.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供用戶體驗、App設(shè)計、網(wǎng)站收錄、網(wǎng)站設(shè)計公司、App開發(fā)、
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)