首页 » ASP代码 » 自动检测目录下的文件的编码

自动检测目录下的文件的编码

这个脚本可以检测目录下所有文件编码,当您需要找到编码不一致的文件时很有用

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

, , , , , ,

转发到新浪微博 转发到新浪微博

目前这篇文章有2条评论(Rss)

  1. wenus | #1
    05/16/2012 at 13:38

    Some really nice and utilitarian information on this site, likewise I conceive the design and style holds great features.

  2. purchase kamagra | #2
    05/16/2012 at 15:44

    多少天留给2012年欧锦赛?

我要评论