Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to determine if it is a file or directory for an item under a folder? [modified]

How to determine if it is a file or directory for an item under a folder? [modified]

Scheduled Pinned Locked Moved Visual Basic
csharptutorialquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JUNEYT
    wrote on last edited by
    #1

    Hi, How could you determine if a read item is a folder or a file in vb.net? For an instance I have read all the files under directory. At the same time there is a sub directory under the directory and I want to get its type. Thanks.

    What a curious mind needs to discover knowledge is noting else than a pin-hole.

    modified on Sunday, February 8, 2009 1:54 PM

    L M 2 Replies Last reply
    0
    • J JUNEYT

      Hi, How could you determine if a read item is a folder or a file in vb.net? For an instance I have read all the files under directory. At the same time there is a sub directory under the directory and I want to get its type. Thanks.

      What a curious mind needs to discover knowledge is noting else than a pin-hole.

      modified on Sunday, February 8, 2009 1:54 PM

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, File attributes would tell you. Here is a C# example, I don't have it in VB.NET:

      	FileInfo info=new FileInfo(fileName);
      	attributes=info.Attributes;
      	bool isFolder=(attributes & FileAttributes.Directory)!=0;
      	...
      

      :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


      M 1 Reply Last reply
      0
      • J JUNEYT

        Hi, How could you determine if a read item is a folder or a file in vb.net? For an instance I have read all the files under directory. At the same time there is a sub directory under the directory and I want to get its type. Thanks.

        What a curious mind needs to discover knowledge is noting else than a pin-hole.

        modified on Sunday, February 8, 2009 1:54 PM

        M Offline
        M Offline
        MohammadAmiry
        wrote on last edited by
        #3
        If IO.File.Exists(Path) Then
           'It is a file
        ElseIf IO.Directory.Exists(Path) Then
           'It is a folder
        End If
        
        1 Reply Last reply
        0
        • L Luc Pattyn

          Hi, File attributes would tell you. Here is a C# example, I don't have it in VB.NET:

          	FileInfo info=new FileInfo(fileName);
          	attributes=info.Attributes;
          	bool isFolder=(attributes & FileAttributes.Directory)!=0;
          	...
          

          :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


          M Offline
          M Offline
          MohammadAmiry
          wrote on last edited by
          #4

          The equivalent vb code is:

            Dim info as New FileInfo(fileName)
            Dim isFolder As Boolean = info.Attributes And FileAttributes.Directory
          
          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups