Change files' encoding recursively on Windows?

后端 未结 5 1295
小鲜肉
小鲜肉 2020-12-08 07:50

Does anybody know a tool, preferably for the Explorer context menu, to recursively change the encoding of files in a project from ISO-8859-1 to UTF-8 and other encodings? Fr

5条回答
  •  一整个雨季
    2020-12-08 08:39

    Here's a nice ASP recursive converter, you need IIS running on your computer:

    
    
    
    Charset Converter - TFI 13/02/2015
    
    
    

    Recursive file charset converter

    by TFI 13/02/2015

    <% totalconverted=0 Function transcoder( ANSIFile) UFT8FileOut=ANSIFile&".tempfile" Set oFS = CreateObject( "Scripting.FileSystemObject" ) Set oFrom = CreateObject( "ADODB.Stream" ) sFFSpec = oFS.GetAbsolutePathName(ANSIFile) Set oTo = CreateObject( "ADODB.Stream" ) sTFSpec = oFS.GetAbsolutePathName(UFT8FileOut) oFrom.Type = 2 'adTypeText oFrom.Charset = fromchar '"Windows-1252" oFrom.Open oFrom.LoadFromFile sFFSpec oTo.Type = 2 'adTypeText oTo.Charset = tochar '"utf-8" oTo.Open oTo.WriteText oFrom.ReadText oTo.SaveToFile sTFSpec,2 oFrom.Close oTo.Close oFS.DeleteFile sFFSpec oFS.MoveFile sTFSpec,sFFSpec End Function Function ConvertFiles(objFolder, sExt, bRecursive, fromchar, tochar) Dim objFile, objSubFolder For each objFile in objFolder.Files If Ucase(fso.GetExtensionName(objFile)) = ucase(sExt) Then transcoder objFile.path totalconverted=totalconverted+1 response.write "• Converted "&fso.GetAbsolutePathName(objFile)&" from "&fromchar&" to "&tochar&"
    " End If Next If bRecursive = true then For each objSubFolder in objFolder.Subfolders ConvertFiles objSubFolder, sExt, true, fromchar, tochar Next End If End Function sFolder=request.form("sFolder") sExtension=request.form("sExtension") fromchar=request.form("fromchar") tochar=request.form("tochar") sSubs=request.form("sSubs") if sSubs="1" then sub1=True else sub1=false end if if len(sExtension)=0 then sExtension="asp" if len(sFolder)>0 and len(fromchar)>0 and len(tochar)>0 then Dim fso, folder, files, NewsFile, sFolder, objFSO, strFileIn, strFileOut Set fso = CreateObject("Scripting.FileSystemObject") 'sFolder = "C:\inetpub\wwwroot\naoutf8" ConvertFiles fso.GetFolder(sFolder), sExtension, Sub1, fromchar, tochar response.write "

    Total files converted: "&totalconverted&"

    New conversion?

    " end if %>
    Folder to process:
    Extension: (default is .asp)
    Process subfolders:
    From charset:
    To charset:

提交回复
热议问题