Use DataGrid to display all files in a directory

xiaoxiao2021-03-06  60

.NET Framework provides two classes that access directory information and two classes of two access file information, key access directory, you can use the Directory category, you can also use the DirectoryInfo class, corresponding to files, and FileInfo classes. The difference between these two classes is that the returned information and the method of use are different. Directory and File classes are static classes, you don't have to create instances when you are using, for example: To delete files, you can file, you want to detect whether the folder is available to Directory.exists (DirectoryPath). The class with INFO must be instantiated when using, and the name or directory name is named in the constructor, so the delete file can be used with Dim MyFile as file = new file (filepath), myfile.delete ().

Both classes provide methods for obtaining all files under a folder or a file for some extension, namely GetFiles ().

'--- Directory example ---- Dim files () as String = Directory.GetFiles (directoryPath [, optionalWildCard])' --- DirectoryInfo example ---- Dim myDir as DirectoryInfo = New DirectoryInfo (directoryPath) Dim fileInfos ( ) as fileInfo = mydir.getfiles ([optionalWildCard])

It is worth noting that the type returned by the two is different, one is an array of String types, and the other is an array of FileInfo types. Below is a binding method:

VB.NET

转载请注明原文地址:https://www.9cbs.com/read-113089.html

New Post(0)