請問你是通過什么得到A文件名的?OpenFileDialog?控件嗎?
站在用戶的角度思考問題,與客戶深入溝通,找到武昌網站設計與武昌網站推廣的解決方案,憑借多年的經驗,讓設計與互聯(lián)網技術結合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:成都網站設計、網站建設、外貿網站建設、企業(yè)官網、英文網站、手機端網站、網站推廣、申請域名、網站空間、企業(yè)郵箱。業(yè)務覆蓋武昌地區(qū)。
假設你的A文件名 是strfilename
直接自己寫函數(shù)進行字符串操作啊
簡單一點
就是去掉末尾的擴展名(4個字符),加上你要的擴展名 譬如 “.pla”
復雜一點寫就是函數(shù)從后到前判斷擴展名的長度,然后截斷這個擴展名加上你要的。
Vb.net獲取某個目錄下文件夾名稱(不包含隱藏文件夾)實現(xiàn)代碼如下:
Dim?dir?As?New?DirectoryInfo("D:\")
For?Each?d?As?DirectoryInfo?In?dir.GetDirectories
ComboBox1.Items.Add(d.Name)
Next
dim?finfo?as?new?fileinfo(d.name)
if?(finfo.attributes?and?FileAttributes.Hidden)FileAttributes.Hidden?then
ComboBox1.Items.Add(d.Name)
end?if
先用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 任務:
獲取方法,參考實例如下:
'獲取路徑名各部分:
如:
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
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
Then
GetFileExtName
".txt"
Else
GetFileExtName
Mid(FilePathFileName,
J,
i)
End
If
End
Function
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()
Dim dDirectory As System.IO.Directory
Dim sName() As String
sName = dDirectory.GetFiles(path)