开发者

Get first file in directory

开发者 https://www.devze.com 2022-12-12 12:15 出处:网络
This is probably pretty basic, but I\'m trying to find out how I can find the first file in a directory?

This is probably pretty basic, but I'm trying to find out how I can find the first file in a directory?

For example, if I've got these line开发者_运维知识库s of code

Dim di as New IO.DirectoryInfo("C:\Test")
Dim aryFi as IO.FileInfo() = di.GetFiles("*.txt")

I can see that the aryFi contains a list of all files, but I need only one and I need the full path of that one file. How can I get it?


Something like:

Dim firstFullPath = di(1).FullPath

(I'm assuming VB.NET is still 1-based. Otherwise di(0).FullPath.)

For production code you should check that the array isn't empty before trying this.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号