請(qǐng)問你是通過什么得到A文件名的?OpenFileDialog?控件嗎?
成都創(chuàng)新互聯(lián)專注于企業(yè)成都營(yíng)銷網(wǎng)站建設(shè)、網(wǎng)站重做改版、尼開遠(yuǎn)網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、成都h5網(wǎng)站建設(shè)、商城建設(shè)、集團(tuán)公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)公司、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁(yè)設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為尼開遠(yuǎn)等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
假設(shè)你的A文件名 是strfilename
直接自己寫函數(shù)進(jìn)行字符串操作啊
簡(jiǎn)單一點(diǎn)
就是去掉末尾的擴(kuò)展名(4個(gè)字符),加上你要的擴(kuò)展名 譬如 “.pla”
復(fù)雜一點(diǎn)寫就是函數(shù)從后到前判斷擴(kuò)展名的長(zhǎng)度,然后截?cái)噙@個(gè)擴(kuò)展名加上你要的。
Vb.net獲取某個(gè)目錄下文件夾名稱(不包含隱藏文件夾)實(shí)現(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
...
可能有更簡(jiǎn)潔的方法,你可以到MSDN看看
System.IO.Directory.GetDirectories:
System.IO.Path.GetFileName:
通用 I/O 任務(wù):
獲取方法,參考實(shí)例如下:
'獲取路徑名各部分:
如:
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
'獲取文件名但不包括擴(kuò)展名
aaa
Public
Function
GetFileNameNoExt(FilePathFileName
As
String)
As
String
'獲取文件名但不包括擴(kuò)展名
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
'=====
'獲取擴(kuò)展名
.txt
Public
Function
GetFileExtName(FilePathFileName
As
String)
As
String
'獲取擴(kuò)展名
.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