VB如何用查找替换的方法批量修改文件名?2个TEXT控件,1个LIST控件

解决方案 »

  1.   

    '改名
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Me.ListBox1.Items.Clear()
            If str = "" Then Exit Sub
            If Me.TextBox1.Text <> "" Then
                col = System.IO.Directory.GetFiles(str)
                For i As Integer = 0 To col.Length - 1
                    oldName = col(i).ToString.Trim
                    bol = oldName.Split(".")
                    newName = str & "/" & Me.TextBox1.Text.ToString.Trim & "." & bol(1)
                    If oldName.Contains(Me.TextBox2.Text.ToString.Trim) Then
                        Rename(oldName, newName)
                    End If
                Next i
            End If
            col = System.IO.Directory.GetFiles(str)
            For i As Integer = 0 To col.Length - 1
                Me.ListBox1.Items.Add(col(i))
            Next i
        End Sub
        '选择目录
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Me.ListBox1.Items.Clear()
            Dim fb As New FolderBrowserDialog
            fb.ShowNewFolderButton = False
            fb.ShowDialog()
            str = fb.SelectedPath
            If str = "" Then Exit Sub
            col = System.IO.Directory.GetFiles(str)
            For i As Integer = 0 To col.Length - 1
                Me.ListBox1.Items.Add(col(i))
            Next i
        End Sub
        '查找文件
        Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            Me.ListBox2.Items.Clear()
            If str = "" Then Exit Sub
            If Me.TextBox2.Text <> "" Then
                col = System.IO.Directory.GetFiles(str)
                For i As Integer = 0 To col.Length - 1
                    If col(i).ToString.Trim.Contains(Me.TextBox2.Text.ToString.Trim) Then
                        Me.ListBox2.Items.Add(col(i))
                    End If
                Next i
            End If
        End Sub
      

  2.   

    FileExists 方法描述如果指定的文件存在,返回 True,若不存在,则返回 False。语法object.FileExists(filespec) FileExists 方法语法有如下几部分:部分 描述 
    object 必需的。始终是一个 FileSystemObject 的名字。 
    filespec 必需的。要确定是否存在的文件的名字。如果认为文件不在当前文件夹中,必须提供一个完整的路径说明(绝对的或相对的)。 
    Private Sub Form_Load()
        Name "E:\学习资料\vb学习\新建 文本文档.txt" As "E:\学习资料\vb学习\test.txt"
    End Sub
      

  3.   

    问题根本就没说清:
    VB如何用查找替换的方法批量修改文件名? 2个TEXT控件,1个LIST控件
    文件名在哪里?在TEXT里?在1个LIST控件?在磁盘上?到哪查找?
    不说清咋干活!
      

  4.   

    文件名显示在LIST中,2个文本框(查找,替换)
      

  5.   

    Private Sub Command1_Click() '查找
    For i = 0 To 10
    p = InStr(Text1.Text, List1.List(i))
    If p = 0 Then GoTo Line
    Do While p <> 0
    p = InStr(p + Len(List1.List(i)), Text1.Text, List1.List(i))
    Text2.Text = Text2.Text & List1.List(i) & vbCrLf
    Loop
    Line:
    Next
    End SubPrivate Sub Command2_Click() '替换
    For i = 0 To 10
    re = Replace(Text1.Text, List1.List(i), "b" & i & ".doc")
    Text1.Text = re
    Next
    End SubPrivate Sub Form_Load()Text2.Text = ""
    Text1.Text = ""
    For i = 0 To 10
    List1.AddItem "a" & i & ".txt"
    Next
    For i = 0 To 20
    Randomize
    k = Int((30 * Rnd) + 1)
    Text1.Text = Text1.Text & "a" & k & ".txt" & vbCrLf
    Next
    End Sub
      

  6.   

    当然可以做了就是要替换真实文件吧??filecopy吧代码楼主自己要去研究,别总想着用复制粘贴的办法解决问题