VB如何用查找替换的方法批量修改文件名?2个TEXT控件,1个LIST控件
解决方案 »
- 自动找查网页中flash句柄的程序
- 关于Button的小小小问题!请各位帮忙看一下~~T_T
- 急!用ADO访问Access时,updata出错提示 定义了过多字段 ,怎么解决 ?
- Data数据控件问题
- 现有记录1万条,用VB+ADO INSERT 添加到access里要30秒,请问如何提高效率!现有记录1万条,用VB+ADO INSERT 添加到access里,请问如
- datareport中细节的内容不显示,是什么原因?
- 怎样隐藏桌面上的图标?
- 已知一个SUB的地址,怎样调用?(在同一工程内)
- 关于VBS程序不能够正常运行
- 帮帮忙!!!
- Vb+Access打包后安装问题
- tol = 0#<BR> 是什么意思?
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
object 必需的。始终是一个 FileSystemObject 的名字。
filespec 必需的。要确定是否存在的文件的名字。如果认为文件不在当前文件夹中,必须提供一个完整的路径说明(绝对的或相对的)。
Private Sub Form_Load()
Name "E:\学习资料\vb学习\新建 文本文档.txt" As "E:\学习资料\vb学习\test.txt"
End Sub
VB如何用查找替换的方法批量修改文件名? 2个TEXT控件,1个LIST控件
文件名在哪里?在TEXT里?在1个LIST控件?在磁盘上?到哪查找?
不说清咋干活!
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