189 8069 5689

vb.net列出文件名 vbnet recordset

VB.net列举文件夹的所有文件

vb.net使用控件folderbrowserdialog1,在程序中:

创新互联公司主营鹰潭网站建设的网络公司,主营网站建设方案,App定制开发,鹰潭h5成都小程序开发搭建,鹰潭网站营销推广欢迎鹰潭等地区企业咨询

'设置对话框中在树视图控件上显示的说明文本

me.folderbrowserdialog1.description

=

"请选择输出报表所在路径:"

'设置从其开始浏览的根文件夹

me.folderbrowserdialog1.selectedpath

=

"c:\"

if

me.folderbrowserdialog1.showdialog()

=

dialogresult.ok

then

'取得全路径(包含文件名)

reportpath1

=

system.io.path.getfullpath(me.folderbrowserdialog1.selectedpath)

'设定text显示文件名

txtreport1.text

=

reportpath1

setreportlist()

end

if

在setreportlist()中针对你所需要的文件进行操作等

VB.NET获取目录文件夹名称

先用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 任务:

vb.net从文件路径中获取文件名

获取方法,参考实例如下:

'获取路径名各部分:

如:

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

VB怎样显示文件夹内所有的文件名称

VB可以使用FileListBox 控件来获取指定文件夹内的所有文件名。

FileListBox 控件,在运行时,在 Path 属性指定的目录中,FileListBox 控件将文件定位并列举出来。该控件用来显示所选择文件类型的文件列表。例如,可以在应用程序中创建对话框,通过它选择一个文件或者一组文件。

以下是组合使用DriveListBox 、控件DirListBox 控件和FileListBox 控件来获取硬盘下任何一个文件夹内的文件名。

Private Sub Dir1_Change()

File1.Path = Dir1.Path

End Sub

Private Sub Drive1_Change()

Dir1.Path = Drive1.Drive

End Sub

Private Sub File1_Click()

Dim i As Long

Debug.Print "目录夹内存在"  File1.ListCount  "个文件。"

End Sub


文章标题:vb.net列出文件名 vbnet recordset
网站链接:http://cdxtjz.cn/article/dojocss.html

其他资讯