大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
请问你是通过什么得到A文件名的?OpenFileDialog?控件吗?
站在用户的角度思考问题,与客户深入沟通,找到武昌网站设计与武昌网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:成都网站设计、网站建设、外贸网站建设、企业官网、英文网站、手机端网站、网站推广、申请域名、网站空间、企业邮箱。业务覆盖武昌地区。
假设你的A文件名 是strfilename
直接自己写函数进行字符串操作啊
简单一点
就是去掉末尾的扩展名(4个字符),加上你要的扩展名 譬如 “.pla”
复杂一点写就是函数从后到前判断扩展名的长度,然后截断这个扩展名加上你要的。
Vb.net获取某个目录下文件夹名称(不包含隐藏文件夹)实现代码如下:
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函数获取子目录的名称(包括其路径),再用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)