bat 文件讀取亂碼問題


使用 for 循環

type file1.txt > file2.txt

文件讀取后可能會出現亂碼,需要在 bat 文件中設置

chcp 65001 

 

表示將批處理設置為 utf-8 編碼,這樣在生成文件和讀取文件時,就會自動設置為 utf-8

code page 列表:

https://docs.microsoft.com/en-us/windows/desktop/intl/code-page-identifiers

 

提供一個簡單的例子:

  

@echo off & setlocal enabledelayedexpansion
chcp 65001

for /f "tokens=*" %%i in (context.txt) do (
    setlocal disabledelayedexpansion
    set line=%%i
    setlocal enabledelayedexpansion
    echo !line!    
)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM