working with sytem.io

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

    working with sytem.io

    Hi,
    I am trying to delete multiple files in a particular directory.
    The code will like this
    \\\
    Dim s As String
    For Each s in Directory.GetFi les(...)
    system.io.file. delete(s)
    Next s
    ///

    Is there a method that would allow me delete more than one file at a time?

    for instance Delete "*.txt"


  • Armin Zingler

    #2
    Re: working with sytem.io

    "ZR" <zvireiss@hotma il.donotspam> schrieb[color=blue]
    > [nothing new][/color]

    It is sufficient to post the question once.


    --
    Armin




    Comment

    • ZR

      #3
      Re: working with sytem.io

      I thought you might have an answer to the question.


      "Armin Zingler" <az.nospam@free net.de> wrote in message
      news:uBJg2FJqDH A.3688@TK2MSFTN GP11.phx.gbl...[color=blue]
      > "ZR" <zvireiss@hotma il.donotspam> schrieb[color=green]
      > > [nothing new][/color]
      >
      > It is sufficient to post the question once.
      >
      >
      > --
      > Armin
      >
      > http://www.plig.net/nnq/nquote.html
      > http://www.netmeister.org/news/learn2quote.html
      >[/color]


      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: working with sytem.io

        * "ZR" <zvireiss@hotma il.donotspam> scripsit:[color=blue]
        > I am trying to delete multiple files in a particular directory.
        > The code will like this
        > \\\
        > Dim s As String
        > For Each s in Directory.GetFi les(...)
        > system.io.file. delete(s)
        > Next s
        > ///
        >
        > Is there a method that would allow me delete more than one file at a time?[/color]

        AFAIK there is no easier way to do what you want. You can use
        'Directory.Dele te' to delete a whole directory.

        --
        Herfried K. Wagner
        MVP · VB Classic, VB.NET
        <http://www.mvps.org/dotnet>

        <http://www.plig.net/nnq/nquote.html>

        Comment

        • ZR

          #5
          Re: working with sytem.io

          thanks alot for your help
          "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
          news:borlvp$1hv 25k$1@ID-208219.news.uni-berlin.de...[color=blue]
          > * "ZR" <zvireiss@hotma il.donotspam> scripsit:[color=green]
          > > I am trying to delete multiple files in a particular directory.
          > > The code will like this
          > > \\\
          > > Dim s As String
          > > For Each s in Directory.GetFi les(...)
          > > system.io.file. delete(s)
          > > Next s
          > > ///
          > >
          > > Is there a method that would allow me delete more than one file at a[/color][/color]
          time?[color=blue]
          >
          > AFAIK there is no easier way to do what you want. You can use
          > 'Directory.Dele te' to delete a whole directory.
          >
          > --
          > Herfried K. Wagner
          > MVP · VB Classic, VB.NET
          > <http://www.mvps.org/dotnet>
          >
          > <http://www.plig.net/nnq/nquote.html>[/color]


          Comment

          • Shawn D Shelton

            #6
            Re: working with sytem.io

            I have some code I will give you that does recursive directory and file
            searches. You can pass the function a wildcard.

            '************** *************** **
            '*
            '* Shawn Shelton
            '* This will search directories for files and directories.
            '* May be recursive if told to.
            '* Use wildcards for searching such as * or .exe
            '*
            Option Explicit On
            Option Strict On
            Imports System
            Imports System.IO
            Imports System.Collecti ons
            Module Searcher
            Public Sub SearchDirectory ForFiles(ByVal dirlist As Stack, ByVal
            searchPath As String, ByVal RecurseDirs As Boolean)
            ' Split searchPath into a directory and a wildcard specification.
            '
            Dim directoryPath As String = Path.GetDirecto ryName(searchPa th)
            Dim search As String = Path.GetFileNam e(searchPath)
            Dim dir As New DirectoryInfo(d irectoryPath)
            If directoryPath Is Nothing Or search Is Nothing Then
            Return
            End If
            Dim f As FileInfo
            Try
            For Each f In dir.GetFiles(se arch)
            dirlist.Push(f. FullName)
            Next
            Catch e As UnauthorizedAcc essException
            Return
            Catch e As DirectoryNotFou ndException
            Return
            End Try

            ' Now that you have finished the files in this directory, recurse for
            ' each subdirectory.
            If RecurseDirs = True Then
            Dim directories As String() = Directory.GetDi rectories(direc toryPath)
            Dim d As String
            For Each d In directories
            SearchDirectory ForFiles(dirlis t, Path.Combine(d, search), True)
            Next d
            End If
            End Sub

            Public Sub SearchDirectory ForDirectories( ByVal dirList As Stack, ByVal
            searchPath As String)
            Dim directoryPath As String = Path.GetDirecto ryName(searchPa th)
            Dim directories As String() = Directory.GetDi rectories(direc toryPath)
            Dim d As String
            For Each d In directories
            dirList.Push(d)
            SearchDirectory ForDirectories( dirList, d & "\")
            Next d
            End Sub

            End Module
            *************** *************

            Call it like this:

            dim dirlist as stack
            dim x as string
            SearchDirectory ForFiles(DirLis t, "c:\winnt\*.txt ", False)
            If DirList.Count > 0 Then
            For Each x In DirList
            SetAttr(x, FileAttribute.N ormal)
            File.Delete(x)
            Next
            End If


            ZR wrote:[color=blue]
            > Hi,
            > I am trying to delete multiple files in a particular directory.
            > The code will like this
            > \\\
            > Dim s As String
            > For Each s in Directory.GetFi les(...)
            > system.io.file. delete(s)
            > Next s
            > ///
            >
            > Is there a method that would allow me delete more than one file at a time?
            >
            > for instance Delete "*.txt"
            >
            >[/color]

            Comment

            • ZR

              #7
              Re: working with sytem.io

              Thanks alot for your help
              "Shawn D Shelton" <shelshaw@isu.e du> wrote in message
              news:uB%233y0Kq DHA.688@TK2MSFT NGP10.phx.gbl.. .[color=blue]
              > I have some code I will give you that does recursive directory and file
              > searches. You can pass the function a wildcard.
              >
              > '************** *************** **
              > '*
              > '* Shawn Shelton
              > '* This will search directories for files and directories.
              > '* May be recursive if told to.
              > '* Use wildcards for searching such as * or .exe
              > '*
              > Option Explicit On
              > Option Strict On
              > Imports System
              > Imports System.IO
              > Imports System.Collecti ons
              > Module Searcher
              > Public Sub SearchDirectory ForFiles(ByVal dirlist As Stack, ByVal
              > searchPath As String, ByVal RecurseDirs As Boolean)
              > ' Split searchPath into a directory and a wildcard specification.
              > '
              > Dim directoryPath As String = Path.GetDirecto ryName(searchPa th)
              > Dim search As String = Path.GetFileNam e(searchPath)
              > Dim dir As New DirectoryInfo(d irectoryPath)
              > If directoryPath Is Nothing Or search Is Nothing Then
              > Return
              > End If
              > Dim f As FileInfo
              > Try
              > For Each f In dir.GetFiles(se arch)
              > dirlist.Push(f. FullName)
              > Next
              > Catch e As UnauthorizedAcc essException
              > Return
              > Catch e As DirectoryNotFou ndException
              > Return
              > End Try
              >
              > ' Now that you have finished the files in this directory, recurse for
              > ' each subdirectory.
              > If RecurseDirs = True Then
              > Dim directories As String() = Directory.GetDi rectories(direc toryPath)
              > Dim d As String
              > For Each d In directories
              > SearchDirectory ForFiles(dirlis t, Path.Combine(d, search), True)
              > Next d
              > End If
              > End Sub
              >
              > Public Sub SearchDirectory ForDirectories( ByVal dirList As Stack, ByVal
              > searchPath As String)
              > Dim directoryPath As String = Path.GetDirecto ryName(searchPa th)
              > Dim directories As String() = Directory.GetDi rectories(direc toryPath)
              > Dim d As String
              > For Each d In directories
              > dirList.Push(d)
              > SearchDirectory ForDirectories( dirList, d & "\")
              > Next d
              > End Sub
              >
              > End Module
              > *************** *************
              >
              > Call it like this:
              >
              > dim dirlist as stack
              > dim x as string
              > SearchDirectory ForFiles(DirLis t, "c:\winnt\*.txt ", False)
              > If DirList.Count > 0 Then
              > For Each x In DirList
              > SetAttr(x, FileAttribute.N ormal)
              > File.Delete(x)
              > Next
              > End If
              >
              >
              > ZR wrote:[color=green]
              > > Hi,
              > > I am trying to delete multiple files in a particular directory.
              > > The code will like this
              > > \\\
              > > Dim s As String
              > > For Each s in Directory.GetFi les(...)
              > > system.io.file. delete(s)
              > > Next s
              > > ///
              > >
              > > Is there a method that would allow me delete more than one file at a[/color][/color]
              time?[color=blue][color=green]
              > >
              > > for instance Delete "*.txt"
              > >
              > >[/color]
              >[/color]


              Comment

              Working...