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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. File? or A Folder?

File? or A Folder?

Scheduled Pinned Locked Moved C#
question
9 Posts 4 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.
  • A Offline
    A Offline
    Adrian Soon
    wrote on last edited by
    #1

    Hi... is there any coding where I can tell a path is a folder or a file? private void FileOrFolder(string path){ if(){//// condition is path is a folder } else if(){/// condition is path is a file } else{/// unknown condition. } }

    C V 2 Replies Last reply
    0
    • A Adrian Soon

      Hi... is there any coding where I can tell a path is a folder or a file? private void FileOrFolder(string path){ if(){//// condition is path is a folder } else if(){/// condition is path is a file } else{/// unknown condition. } }

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      I believe that File.Exists is one way to find out if something is a file.

      Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      S A 2 Replies Last reply
      0
      • C Christian Graus

        I believe that File.Exists is one way to find out if something is a file.

        Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        S Offline
        S Offline
        Spacix One
        wrote on last edited by
        #3

        There is also Directory.Exist in System.IO it is part of File


        -Spacix All your skynet questions[^] belong to solved

        1 Reply Last reply
        0
        • C Christian Graus

          I believe that File.Exists is one way to find out if something is a file.

          Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

          A Offline
          A Offline
          Adrian Soon
          wrote on last edited by
          #4

          in my coding format how should I put it??? if(File.Exist(path)){ } else if(){ /// Find whether is folder? } else{ }

          C 1 Reply Last reply
          0
          • A Adrian Soon

            in my coding format how should I put it??? if(File.Exist(path)){ } else if(){ /// Find whether is folder? } else{ }

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            Assuming you don't already know it's a folder, use Directory.Exists as well. I assumed you knew it was one or the other, in which case, File.Exists would answer the question

            Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

            A 1 Reply Last reply
            0
            • C Christian Graus

              Assuming you don't already know it's a folder, use Directory.Exists as well. I assumed you knew it was one or the other, in which case, File.Exists would answer the question

              Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

              A Offline
              A Offline
              Adrian Soon
              wrote on last edited by
              #6

              ok thanks... if it is a folder.. I wish to know whether is there any file inside.. is there a shortest possible coding?

              C 1 Reply Last reply
              0
              • A Adrian Soon

                ok thanks... if it is a folder.. I wish to know whether is there any file inside.. is there a shortest possible coding?

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #7

                It's either File.GetAllFiles or Directory.GetAllFiles, returns a string array of file names.

                Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

                A 1 Reply Last reply
                0
                • A Adrian Soon

                  Hi... is there any coding where I can tell a path is a folder or a file? private void FileOrFolder(string path){ if(){//// condition is path is a folder } else if(){/// condition is path is a file } else{/// unknown condition. } }

                  V Offline
                  V Offline
                  Vasudevan Deepak Kumar
                  wrote on last edited by
                  #8

                  Will this help you? http://www.devcity.net/PrintArticle.aspx?ArticleID=16[^]

                  Vasudevan Deepak Kumar Personal Homepage Tech Gossips

                  1 Reply Last reply
                  0
                  • C Christian Graus

                    It's either File.GetAllFiles or Directory.GetAllFiles, returns a string array of file names.

                    Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

                    A Offline
                    A Offline
                    Adrian Soon
                    wrote on last edited by
                    #9

                    U means Directory.GetFiles? but it only get the files. hai. think I there isn't a faster way then.. hehe

                    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