Convert multiple files to UTF-8 encoding with Notepad++

文章推薦指數: 80 %
投票人數:10人

This file will search all files and folders within a given directory, and use Notepad++ to convert their encoding to UTF-8 without Byte Order Marks. Skiptocontent Allgists BacktoGitHub Signin Signup Sign in Sign up {{message}} Instantlysharecode,notes,andsnippets. smccutchen/ConvertUTF-8.py CreatedJan4,2017 Star 6 Fork 7 Star Code Revisions 1 Stars 6 Forks 7 Embed Whatwouldyouliketodo? Embed Embedthisgistinyourwebsite. Share Copysharablelinkforthisgist. Clonevia HTTPS ClonewithGitorcheckoutwithSVNusingtherepository’swebaddress. LearnmoreaboutcloneURLs DownloadZIP ConvertmultiplefilestoUTF-8encodingwithNotepad++ Raw ConvertUTF-8.py ThisfilecontainsbidirectionalUnicodetextthatmaybeinterpretedorcompileddifferentlythanwhatappearsbelow.Toreview,openthefileinaneditorthatrevealshiddenUnicodecharacters. LearnmoreaboutbidirectionalUnicodecharacters Showhiddencharacters #2016-2017SoveranceStudios. #ScottMcCutchen #Thisfilewillsearchallfilesandfolderswithinagivendirectory,anduseNotepad++toconverttheirencodingtoUTF-8withoutByteOrderMarks # #ThisfilemustberunusingthePythonScriptpluginfromwithinNotepad++,whichisavailablethroughtheNotepad++PluginManager # #YoumusthavePython2.7installed # #Additionally,thisscriptcanonlyexistandberunfromwithintheNotepad++user'sworkingdirectory,thedefaultofwhichishere: #Notethatselecting"NewScript"fromwithinthePythonScriptpluginwillautomaticallydefaulttothissavelocation #..USERDIRECTORY\AppData\Roaming\Notepad++\plugins\Config\PythonScript\scripts importos; importsys; fromNppimportnotepad filePathSrc="U:\\UnrealEngine\\Ethereal\\Source\\Ethereal"#Pathtothefolderwithfilestoconvert forroot,dirs,filesinos.walk(filePathSrc): forfninfiles: iffn[-2:]=='.h'orfn[-4:]=='.cpp':#Specifyfiletypes,takingcaretochangethefn[number]tocorrespondtolengthofthefile'sextensionincludingthe. notepad.open(root+"\\"+fn) notepad.runMenuCommand("Encoding","EncodeinANSI") notepad.runMenuCommand("Encoding","ConverttoUTF-8") notepad.save() notepad.close() Copylink LulaSvob commented Sep20,2018 • edited Hereisanimprovedversionthatprintstheactionintheconsoleandalsoaccountsfornon-LatincharacterslikeCyrillic,Japanese,Chineseetc...inthepath #-*-coding:utf-8-*- importos importsys fromNppimportnotepad filePathSrc="D:\\Файлове\\"#Pathtothefolderwithfilestoconvert filePathSrc=filePathSrc.decode('utf-8') os.chdir(filePathSrc) forroot,dirs,filesinos.walk(".",topdown=False): forfninfiles: iffn[-4:]=='.txt': notepad.open(root+"\\"+fn) notepad.runMenuCommand("Encoding","ConverttoUTF-8") notepad.save() console.write('File'+fn+'saved.Closing...\n') notepad.close() Sorry,somethingwentwrong. Copylink Joppest commented Nov15,2019 Thanks!Had~65ksmalltextfileswhereevery1000orsotherewasa0x90charactermessingupmyprocessing! Sorry,somethingwentwrong. Copylink TurtleShroom commented Apr27,2021 Doesthisscriptworkonfoldertrees,withsub-folders? Sorry,somethingwentwrong. Signupforfree tojointhisconversationonGitHub. Alreadyhaveanaccount? Signintocomment Youcan’tperformthatactionatthistime. Yousignedinwithanothertaborwindow.Reloadtorefreshyoursession. Yousignedoutinanothertaborwindow.Reloadtorefreshyoursession.



請為這篇文章評分?