Get filenames

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Niels

    Get filenames

    Hello, i want to read out the file names of a directory.
    The previous time, i got this piece of code from someone,
    but this code counts the number of files in a directory.

    My intentions are to get the filenames (without extension)
    in a combobox....
    ~~~~~~~~~~
    Code
    ~~~~~~~~~~
    Imports System
    Imports System.IO



    Dim di As DirectoryInfo = New DirectoryInfo(" c:\")
    Try
    Dim dirs As FileSystemInfo( ) = di.GetDirectori es("*p*")
    Console.WriteLi ne("Number of directories with a p: _
    {0}", dirs.Length)
    Dim diNext As DirectoryInfo
    For Each diNext In dirs
    Console.WriteLi ne("The number of files and _
    directories " + "in {0} with an e is {1}", diNext, _
    diNext.GetFileS ystemInfos("*e* ").Length)
    Next
    Catch e As Exception
    Console.WriteLi ne("The process failed: {0}", _
    e.ToString())
    End Try
    ~~~~~~~~~~
    Code
    ~~~~~~~~~~

    Can anyone help me???
  • Armin Zingler

    #2
    Re: Get filenames

    "Niels" <nielsh@holandr idderkerk.nl> schrieb[color=blue]
    > Hello, i want to read out the file names of a directory.
    > The previous time, i got this piece of code from someone,
    > but this code counts the number of files in a directory.
    >
    > My intentions are to get the filenames (without extension)
    > in a combobox....
    > ~~~~~~~~~~
    > Code
    > ~~~~~~~~~~
    > Imports System
    > Imports System.IO
    >
    >
    >
    > Dim di As DirectoryInfo = New DirectoryInfo(" c:\")[/color]


    Call di.GetFiles instead of di.GetDirectori es. In a loop, call
    System.IO.Path. GetFileNameWith outExtension and add the return value to the
    combobox. Pass the Name property of each FileInfo object returned by
    di.GetFiles to GetFileNameWith outExtension.


    --
    Armin

    How to quote and why:



    Comment

    • Armin Zingler

      #3
      Re: Get filenames

      "Niels" <nielsh@holandr idderkerk.nl> schrieb[color=blue]
      > Hello, i want to read out the file names of a directory.
      > The previous time, i got this piece of code from someone,
      > but this code counts the number of files in a directory.
      >
      > My intentions are to get the filenames (without extension)
      > in a combobox....
      > ~~~~~~~~~~
      > Code
      > ~~~~~~~~~~
      > Imports System
      > Imports System.IO
      >
      >
      >
      > Dim di As DirectoryInfo = New DirectoryInfo(" c:\")[/color]


      Call di.GetFiles instead of di.GetDirectori es. In a loop, call
      System.IO.Path. GetFileNameWith outExtension and add the return value to the
      combobox. Pass the Name property of each FileInfo object returned by
      di.GetFiles to GetFileNameWith outExtension.


      --
      Armin

      How to quote and why:



      Comment

      • Thom

        #4
        Re: Get filenames

        Here is the way I do it....
        fileNameArray = System.IO.Direc tory.GetFiles(" C:\", "*.")



        "Armin Zingler" <az.nospam@free net.de> wrote in message
        news:406d50e3$0 $12483$9b622d9e @news.freenet.d e...[color=blue]
        > "Niels" <nielsh@holandr idderkerk.nl> schrieb[color=green]
        > > Hello, i want to read out the file names of a directory.
        > > The previous time, i got this piece of code from someone,
        > > but this code counts the number of files in a directory.
        > >
        > > My intentions are to get the filenames (without extension)
        > > in a combobox....
        > > ~~~~~~~~~~
        > > Code
        > > ~~~~~~~~~~
        > > Imports System
        > > Imports System.IO
        > >
        > >
        > >
        > > Dim di As DirectoryInfo = New DirectoryInfo(" c:\")[/color]
        >
        >
        > Call di.GetFiles instead of di.GetDirectori es. In a loop, call
        > System.IO.Path. GetFileNameWith outExtension and add the return value to the
        > combobox. Pass the Name property of each FileInfo object returned by
        > di.GetFiles to GetFileNameWith outExtension.
        >
        >
        > --
        > Armin
        >
        > How to quote and why:
        > http://www.plig.net/nnq/nquote.html
        > http://www.netmeister.org/news/learn2quote.html
        >[/color]


        Comment

        • Thom

          #5
          Re: Get filenames

          Here is the way I do it....
          fileNameArray = System.IO.Direc tory.GetFiles(" C:\", "*.")



          "Armin Zingler" <az.nospam@free net.de> wrote in message
          news:406d50e3$0 $12483$9b622d9e @news.freenet.d e...[color=blue]
          > "Niels" <nielsh@holandr idderkerk.nl> schrieb[color=green]
          > > Hello, i want to read out the file names of a directory.
          > > The previous time, i got this piece of code from someone,
          > > but this code counts the number of files in a directory.
          > >
          > > My intentions are to get the filenames (without extension)
          > > in a combobox....
          > > ~~~~~~~~~~
          > > Code
          > > ~~~~~~~~~~
          > > Imports System
          > > Imports System.IO
          > >
          > >
          > >
          > > Dim di As DirectoryInfo = New DirectoryInfo(" c:\")[/color]
          >
          >
          > Call di.GetFiles instead of di.GetDirectori es. In a loop, call
          > System.IO.Path. GetFileNameWith outExtension and add the return value to the
          > combobox. Pass the Name property of each FileInfo object returned by
          > di.GetFiles to GetFileNameWith outExtension.
          >
          >
          > --
          > Armin
          >
          > How to quote and why:
          > http://www.plig.net/nnq/nquote.html
          > http://www.netmeister.org/news/learn2quote.html
          >[/color]


          Comment

          • M. Angelo

            #6
            Re: Get filenames

            Microsoft.Visua lBasic.Compatib ility.VB6.FileL istBox

            Niels wrote:
            [color=blue]
            > Hello, i want to read out the file names of a directory.
            > The previous time, i got this piece of code from someone,
            > but this code counts the number of files in a directory.
            >
            > My intentions are to get the filenames (without extension)
            > in a combobox....
            > ~~~~~~~~~~
            > Code
            > ~~~~~~~~~~
            > Imports System
            > Imports System.IO
            >
            >
            >
            > Dim di As DirectoryInfo = New DirectoryInfo(" c:\")
            > Try
            > Dim dirs As FileSystemInfo( ) = di.GetDirectori es("*p*")
            > Console.WriteLi ne("Number of directories with a p: _
            > {0}", dirs.Length)
            > Dim diNext As DirectoryInfo
            > For Each diNext In dirs
            > Console.WriteLi ne("The number of files and _
            > directories " + "in {0} with an e is {1}", diNext, _
            > diNext.GetFileS ystemInfos("*e* ").Length)
            > Next
            > Catch e As Exception
            > Console.WriteLi ne("The process failed: {0}", _
            > e.ToString())
            > End Try
            > ~~~~~~~~~~
            > Code
            > ~~~~~~~~~~
            >
            > Can anyone help me???[/color]

            Comment

            • M. Angelo

              #7
              Re: Get filenames

              Microsoft.Visua lBasic.Compatib ility.VB6.FileL istBox

              Niels wrote:
              [color=blue]
              > Hello, i want to read out the file names of a directory.
              > The previous time, i got this piece of code from someone,
              > but this code counts the number of files in a directory.
              >
              > My intentions are to get the filenames (without extension)
              > in a combobox....
              > ~~~~~~~~~~
              > Code
              > ~~~~~~~~~~
              > Imports System
              > Imports System.IO
              >
              >
              >
              > Dim di As DirectoryInfo = New DirectoryInfo(" c:\")
              > Try
              > Dim dirs As FileSystemInfo( ) = di.GetDirectori es("*p*")
              > Console.WriteLi ne("Number of directories with a p: _
              > {0}", dirs.Length)
              > Dim diNext As DirectoryInfo
              > For Each diNext In dirs
              > Console.WriteLi ne("The number of files and _
              > directories " + "in {0} with an e is {1}", diNext, _
              > diNext.GetFileS ystemInfos("*e* ").Length)
              > Next
              > Catch e As Exception
              > Console.WriteLi ne("The process failed: {0}", _
              > e.ToString())
              > End Try
              > ~~~~~~~~~~
              > Code
              > ~~~~~~~~~~
              >
              > Can anyone help me???[/color]

              Comment

              • Cor

                #8
                Re: Get filenames

                Hi Niels,

                That page did gave a lot of samples when you went on in it, but this I added
                also to your other question.

                \\\
                Private Sub Button1_Click(B yVal sender As _
                System.Object, ByVal e As System.EventArg s) Handles Button1.Click
                Dim mypath As String
                mypath = Application.Sta rtupPath
                Dim Dirs As IO.DirectoryInf o = New IO.DirectoryInf o(mypath &
                "\Stamps\")
                Dim FileCount As IO.FileSystemIn fo() = Dirs.GetFiles
                Dim FileNaam As IO.FileInfo
                ComboBox1.Items .Clear()
                ComboBox1.Items .AddRange(FileC ount)
                ComboBox1.Selec tedIndex = 0
                End Sub
                ///
                Cor


                Comment

                • Cor

                  #9
                  Re: Get filenames

                  Hi Niels,

                  That page did gave a lot of samples when you went on in it, but this I added
                  also to your other question.

                  \\\
                  Private Sub Button1_Click(B yVal sender As _
                  System.Object, ByVal e As System.EventArg s) Handles Button1.Click
                  Dim mypath As String
                  mypath = Application.Sta rtupPath
                  Dim Dirs As IO.DirectoryInf o = New IO.DirectoryInf o(mypath &
                  "\Stamps\")
                  Dim FileCount As IO.FileSystemIn fo() = Dirs.GetFiles
                  Dim FileNaam As IO.FileInfo
                  ComboBox1.Items .Clear()
                  ComboBox1.Items .AddRange(FileC ount)
                  ComboBox1.Selec tedIndex = 0
                  End Sub
                  ///
                  Cor


                  Comment

                  Working...