获取目录中每个文件的文件名 [英] Get a filename for every file in a directory

查看:147
本文介绍了获取目录中每个文件的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我这里有个情况.我尝试在互联网上搜索,但对我不起作用.情况是我已经声明了一个路径并计算了具有该扩展名的现有文件.这是代码:

Hi all,

I have a situation here. I try to search in the internet but it doesn''t work for me. The situation is I have declare a path and counting the existed file with that extension have. This are the code:

Dim path As String = "C:\FTP\Backup\"
Dim i As Integer
Dim FileCount As Integer = IO.Directory.GetFiles(path, "*.jpg").Length
''count the number of existing file with specific ext. in a path

Dim fileName(FileCount - 1) As String ''represent as array
Dim fileInfo As New FileInfo(path)

If FileCount <> 0 Then
    For i = 1 To FileCount
        fileName(i) = fileInfo.Name ''array will hold the file name from file info
    Next
End If



我不知道该怎么解决.假设我有10个扩展名为".jpg"的文件,并且我想在数组的每个计数中保留文件名,以便可以一个一个地显示它.我知道我的代码运行不正常.请帮助我..我为此停留了两天.帮助我



I don''t know how to solve this. Let say I have 10 files with ".jpg" extension and I want to hold the filename in every count in an array so I can display it one by one. I know my code is not doing properly. Please help me..I stuck for 2days for this. Help me

推荐答案

如果只需要文件名,为什么不直接获取它们呢?
If all you want if the file names, why not just get them?
Dim matching As String() = Directory.GetFiles(path, "*.jpg")


这篇关于获取目录中每个文件的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆