如何将 DirectoryInfo 文件转换为字符串

发布于 2024-08-28 20:41:16 字数 582 浏览 2 评论 0原文

问题是我无法转换为字符串

Dim path As String = "..\..\..\Tier1 downloads\CourseVB\"


If countNumberOfFolders > 0 Then 'if there is a folder then


    ' make a reference to a directory
    Dim di As New IO.DirectoryInfo(path)
    Dim diar1 As IO.DirectoryInfo() = di.GetDirectories()
    Dim dra As IO.DirectoryInfo

    'list the names of all files in the specified directory
    For Each dra In diar1

        Dim lessonDirectoryName() As Lesson
        lessonDirectoryName(0).lessonName = dra

    Next

'课程是一个对象,而lessonName是字符串类型的属性。如何将目录信息转换为字符串?

Problem is that i cant convert to string

Dim path As String = "..\..\..\Tier1 downloads\CourseVB\"


If countNumberOfFolders > 0 Then 'if there is a folder then


    ' make a reference to a directory
    Dim di As New IO.DirectoryInfo(path)
    Dim diar1 As IO.DirectoryInfo() = di.GetDirectories()
    Dim dra As IO.DirectoryInfo

    'list the names of all files in the specified directory
    For Each dra In diar1

        Dim lessonDirectoryName() As Lesson
        lessonDirectoryName(0).lessonName = dra

    Next

'the the lesson is an object, and lessonName is the property of type string. How do i convert the directoryInfo to string?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

纸短情长 2024-09-04 20:41:16

DirectoryInfo 有一个 FullName 属性,它是字符串形式的目录路径。

DirectoryInfo has a FullName property which is the path of the directory as a string.

孤独岁月 2024-09-04 20:41:16

您的注释与您的代码冲突,并且您的代码看起来有点错误。我想你想要这样的东西:

Dim lessonDirectoryNames As New List(Lesson)        
If Directory.Exists(path) Then
    For Each fileName as String In Directory.GetFiles(path)
        Dim les as New Lesson
        les.lessonName = fileName
        lessonDirectoryName.Add(les)
    Next 
End If

Your comments conflict with your code and your code looks a little bit buggy. I think you want something like:

Dim lessonDirectoryNames As New List(Lesson)        
If Directory.Exists(path) Then
    For Each fileName as String In Directory.GetFiles(path)
        Dim les as New Lesson
        les.lessonName = fileName
        lessonDirectoryName.Add(les)
    Next 
End If
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文