使用VBS批量修改文件夹名

批量修改文件名的软件有不少,但是能批量修改文件夹名称的可不多。如果各位有好的软件,请留言告知Pop,谢谢。

下面是利用VBS的脚本进行批量修改文件夹名,经过Pop的测试,效果还很不错的。

使用方法:
把下面的代码复制保存为 *.vbs 的格式,如1.vbs,然后双击这个文件就可以开始批量修改文件夹名了。

Dim NewLine
NewLine = vbcrlf
TabStop = ""

function isFolderExists(fso,folderPath)
if folderPath = empty then exit function
If not FSO.FolderExists(folderPath) Then
msgbox "foloder not exists!please try agian"
folderPath = InputBox("请输入路径[绝对路径],为空则自动退出","")
call isFolderExists(fso,folderPath)
end if
end function

Function doRepWord(Files,repWord,resWord)

Dim S,file,count
repWord = split(repWord,";")
count = 0
For Each File In Files
for each repStr in repWord
if instr(File.Name,repStr)<>0 then
file.name = replace(file.name,repStr,resWord)
count = count + 1
end if
next
Next

doRepWord = count

End Function

sub reName()
dim s,folderPath,repWord,resWord
folderPath = "F:\Pop\Pic"
folderPath = InputBox("批量替换文件夹名称"& chr(13) &"请输入路径[绝对路径]","")

Set fso = CreateObject("Scripting.FileSystemObject")
call isFolderExists(fso,folderPath)
if folderPath = empty then exit sub
repWord = InputBox("希望要替换掉的字符,多个字符请用分号[;]隔开!","")
resWord = InputBox("希望将字符替换为:!","")

Set Folder = FSO.GetFolder(folderPath)
Set Files = Folder.SubFolders

If 1 = Files.Count Then
S = S & "There is only 1 folder" &NewLine
Else
S = S & "There are " & Files.Count &" folders "&NewLine
End If

If Files.Count <> 0 Then
s = s & "replace folderName:" & doRepWord(Files,repWord,resWord) &NewLine
End If

if 1 = 2 then

Set Files = Folder.Files

If 1 = Files.Count Then
S = S & "There is 1 file" & NewLine
Else
S = S & "There are " & Files.Count & " folders" & NewLine
End If

If Files.Count <> 0 Then
s = s & "replace folder:" & doRepWord(Files,repWord,resWord) &NewLine
End If

end if

msgbox s

end sub

call reName()

原文地址:
http://www.cnblogs.com/avill/archive/2006/03/02/341424.html

This entry was posted in Technology and tagged , . Bookmark the permalink. 10,245 views

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>