梦想吧技术论坛's Archiver

似水年华 发表于 2007-4-22 06:40 PM

VBS-批量修改文件扩展名

将 C:\Scripts 文件夹中的所有 .log 文件的文件扩展名更改为 .txt

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set FileList = objWMIService.ExecQuery _
    ("ASSOCIATORS OF {Win32_Directory.Name='c:\Scripts'} Where " _
        & "ResultClass = CIM_DataFile")
For Each objFile In FileList
    If objFile.Extension = "log" Then
        strNewName = objFile.Drive & objFile.Path & _
            objFile.FileName & "." & "txt"
        errResult = objFile.Rename(strNewName)
        Wscript.Echo errResult
    End If
Next

页: [1]

Powered by Discuz! Archiver 7.0.0  © 2001-2009 Comsenz Inc.