自动检测目录下的文件的编码
这个脚本可以检测目录下所有文件的编码,当您需要找到编码不一致的文件时很有用
Dim fso,level,StartPath,nFold,nFile Set fso = CreateObject("scripting.filesystemobject") StartPath= "D:\wwwroot\testuser\wwwroot" : level=0 : nFold=0 :nFile=0 Call getallfolder(StartPath) Call getallfile(StartPath) WScript.Echo "检测完成" WScript.Echo "文件夹:" & nFold WScript.Echo "文件数:" & nFile Function checkcode(byval path) set objstream=CreateObject("adodb.stream") objstream.Type=1 objstream.mode=3 objstream.open objstream.Position=0 objstream.loadfromfile path bintou=objstream.read(2) If AscB(MidB(bintou,1,1))=&HEF And AscB(MidB(bintou,2,1))=&HBB Then checkcode="utf-8" ElseIf AscB(MidB(bintou,1,1))=&HFF And AscB(MidB(bintou,2,1))=&HFE Then checkcode="unicode" Else checkcode="gb2312" End If objstream.close set objstream=nothing end Function Sub getallfolder(path) Set objfolder=fso.GetFolder(path) Set objSubFolders=objFolder.SubFolders : Set objfolder=Nothing For each objSubFolder in objSubFolders level=level+1 : nFold=nFold+1 WScript.Echo Space(level * 2) & objSubFolder.Name nowpath=path & "\" & objSubFolder.Name Call getallfolder(nowpath) Call getallfile(nowpath) level=level-1 Next End Sub Sub getallfile(fold) Set objfiles=fso.GetFolder(fold) For Each objfile In objfiles.Files ffname=objfile.Path if checkcode(ffname)="gb2312" Then WScript.Echo ffname End If nFile=nFile+1 Next Set objfiles=Nothing End Sub
上一篇: 用vbs脚本来读取windows性能计数器中的数据
下一篇: 创建特殊文件夹删除特殊文件夹
目前这篇文章有2条评论(Rss)