Rename multiple files like windows does...

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

    Rename multiple files like windows does...

    Hello....

    i want to know if its posible to rename multiple files like windows does..

    example:

    file zzzzzzz.doc
    file asdasd.doc
    file esfsefse.doc

    if you select the three files and rename it, windows put this way..

    file(1).doc
    file(2).doc
    file(3).doc

    is there any vb.net way of doing this?


    thanks!!!
    --
    Salute by the First Time!
  • Herfried K. Wagner [MVP]

    #2
    Re: Rename multiple files like windows does...

    "Rothariger " <Rothariger@msn .com> schrieb:[color=blue]
    > i want to know if its posible to rename multiple files like windows does..
    >
    > example:
    >
    > file zzzzzzz.doc
    > file asdasd.doc
    > file esfsefse.doc
    >
    > if you select the three files and rename it, windows put this way..[/color]

    Check out VB.NET's 'Rename' function, which can be used to rename files and
    directories.

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://classicvb.org/petition/>

    Comment

    • Rothariger

      #3
      Re: Rename multiple files like windows does...

      may be i didnt explain very well...

      but i was talking about of doing automatically.. . rename all the files
      automatically.. . i was using the system.io.file. move, but then i must to
      check if the file exists and make it automatically.. . but i was thinking that
      may be the windows api make it automatically.. .


      --
      Salute by the First Time!


      "Herfried K. Wagner [MVP]" wrote:
      [color=blue]
      > "Rothariger " <Rothariger@msn .com> schrieb:[color=green]
      > > i want to know if its posible to rename multiple files like windows does..
      > >
      > > example:
      > >
      > > file zzzzzzz.doc
      > > file asdasd.doc
      > > file esfsefse.doc
      > >
      > > if you select the three files and rename it, windows put this way..[/color]
      >
      > Check out VB.NET's 'Rename' function, which can be used to rename files and
      > directories.
      >
      > --
      > M S Herfried K. Wagner
      > M V P <URL:http://dotnet.mvps.org/>
      > V B <URL:http://classicvb.org/petition/>
      >
      >[/color]

      Comment

      • Ross Presser

        #4
        Re: Rename multiple files like windows does...

        On Mon, 22 Aug 2005 12:48:06 -0700, Rothariger wrote:
        [color=blue]
        > may be i didnt explain very well...
        >
        > but i was talking about of doing automatically.. . rename all the files
        > automatically.. . i was using the system.io.file. move, but then i must to
        > check if the file exists and make it automatically.. . but i was thinking that
        > may be the windows api make it automatically.. .[/color]

        Nope. The behavior you describe is programmed in the shell, not the API; so
        you must program it yourself.

        Comment

        • Ronchese

          #5
          Re: Rename multiple files like windows does...

          Use a function (below) that I developed for a mine program. I've used that
          to rename nodes in a treeview, but you can adapt to check for folders
          instead a treenode.


          Use:
          ParentTreeNode: is a treeview (you can change it to a folder, but you will
          need to adapt de code inside function to folder, too)
          DefaultName: is the name the user typed in your programa (in you example,
          "file")


          Change it as well :))



          Public Function GenerateNewNode Name(ByVal ParentTreeNode As TreeNode,
          ByVal DefaultName As String) As String
          Dim i As Integer
          Dim lngHighNumber As Long
          Dim strNewName As String

          If ParentTreeNode. Nodes.Count = 0 Then
          Return DefaultName
          Else
          Dim strRegex As String = "/" & DefaultName & "/|/" & DefaultName
          & "\s+\([0-9]*\)/"
          strRegex = strRegex.Replac e(" ", "\s")
          Dim options As System.Text.Reg ularExpressions .RegexOptions =
          ((System.Text.R egularExpressio ns.RegexOptions .IgnorePatternW hitespace) _
          Or
          System.Text.Reg ularExpressions .RegexOptions.I gnoreCase)
          Dim cRegExp As System.Text.Reg ularExpressions .Regex = New
          System.Text.Reg ularExpressions .Regex(strRegex , options)
          Dim cMatches As System.Text.Reg ularExpressions .MatchCollectio n
          Dim cMatch As System.Text.Reg ularExpressions .Match
          Dim tnodNode As TreeNode
          Dim strMatchValue As String
          Dim strNodeNames As String
          Dim cString As New Text.StringBuil der
          Dim blnFound As Boolean

          'transfer all nodes to a string
          cString.Remove( 0, cString.Length)
          For Each tnodNode In ParentTreeNode. Nodes
          cString.Append( "/")
          cString.Append( tnodNode.Text)
          cString.Append( "/")
          Next
          strNodeNames = cString.ToStrin g

          'check for matches
          cMatches = cRegExp.Matches (strNodeNames)

          'initializes the return
          strNewName = DefaultName

          'find the new name
          i = -1
          While True
          i = i + 1
          blnFound = False
          For Each cMatch In cMatches
          If i = 0 Then
          strNewName = DefaultName
          Else
          strNewName = DefaultName & " (" & i & ")"
          End If
          If cMatch.Value.Re place("/", "") = strNewName Then
          blnFound = True
          Exit For
          End If
          Next
          If Not blnFound Then Return strNewName
          End While


          'return default
          Return strNewName
          End If

          End Function







          "Rothariger " <Rothariger@msn .com> escreveu na mensagem
          news:1888596C-4993-40C2-9DD9-DCE2AA5113BA@mi crosoft.com...
          Hello....

          i want to know if its posible to rename multiple files like windows does..

          example:

          file zzzzzzz.doc
          file asdasd.doc
          file esfsefse.doc

          if you select the three files and rename it, windows put this way..

          file(1).doc
          file(2).doc
          file(3).doc

          is there any vb.net way of doing this?


          thanks!!!
          --
          Salute by the First Time!




          Comment

          • Herfried K. Wagner [MVP]

            #6
            Re: Rename multiple files like windows does...

            "Rothariger " <Rothariger@msn .com> schrieb:[color=blue]
            > but i was talking about of doing automatically.. . rename all the files
            > automatically.. . i was using the system.io.file. move, but then i must to
            > check if the file exists and make it automatically.. . but i was thinking
            > that
            > may be the windows api make it automatically.. .[/color]

            AFAIK the .NET Framework doesn't provide a method for automatic renaming.
            You'll have to implement this behavior yourself.

            --
            M S Herfried K. Wagner
            M V P <URL:http://dotnet.mvps.org/>
            V B <URL:http://classicvb.org/petition/>

            Comment

            Working...