VB 如何批量修改文件夹内的文件名

解决方案 »

  1.   


    Private Sub Form_Load()
    Dim MyFile, MyPath, MyName
    MyPath = "D:\test\"   ' 指定路径。
    MyName = Dir(MyPath, vbNormal)   ' 找寻第一项。
      i = 0
    Do While MyName <> ""   ' 开始循环。
       ' 跳过当前的目录及上层目录。
          If MyName <> "." And MyName <> ".." Then
          ' 使用位比较来确定 MyName 代表一目录。
          If (GetAttr(MyPath & MyName) And vbDirectory) = vbNormal Then
              
              If Right(MyName, 4) = ".jpg" Then
              i = i + 1
             Name MyPath & MyName As MyPath & "00" & i & ".jpg"
               End If
            End If
           End If
       MyName = Dir   ' 查找下一个目录。
    Loop
    End Sub批量重命名图片的程序
      

  2.   

    使用dos命令ren啊,语法帮助里就有。
      

  3.   

    首先在C盘下建立CRY文件夹,在里面放置很多TXT文件
    Private Sub Command1_Click()
    Dim s As String
    Dim sFullPath As String
    Dim i As Integer
    s = Dir("c:\cry\*.txt")     '查询所有TXT文件
    While LenB(s) <> 0          '文件名称字节长度不为0,也就是文件存在
        If (s <> ".") And (s <> "..") Then
            sFullPath = "c:\cry\" & s  ’文件全路径名称
            If (GetAttr(sFullPath) And vbDirectory) <> vbDirectory Then   ’判断次文件不是文件夹
                i = i + 1
                Name sFullPath As "c:\cry\" & i & ".txt"   ’在这里修改文件名字
            End If
        End If
        s = Dir()   ’查找下一个文件
    WendEnd Sub
    测试通过
      

  4.   


    修改文件名用 NAME函数不行??
      

  5.   

    用3楼的ren,难道不行?'在我的e:\temp下面有2个文件Form1.frm,Form1.frx,用下面这行VB程序可以的
    Shell "c:\windows\system32\cmd.exe /c ren e:\temp\Form1.* vbForm1.*"