批量转换文件编码gb2312转utf-8
批量转换文件编码gb2312转utf-8
锟斤拷烫烫烫
这几天网上找代码学习用vscode打开之后中文全是乱码,转换编码为 gb2312
后才正常显示,之前也因为这玩意狠狠的踩坑( Keil
默认的编码对中文来说太坑了。但是一个工程里文件很多,所以就需要一个批量把这些文件转换为 utf-8
的脚本。

参考博客
关于文件编码
b站上找到的这个视频挺好。
「烫烫屯屯锟斤拷」揭秘ASCII、GBK、UTF-8,B站独家,一听就懂
脚本
其实网上随便一搜就有好多,试了一个效果不错,但是只能转换根目录下的文件。于是我稍微做了点修改。
效果还是不错的
运行结果
请输入要转换编码的文件夹路径:C:\Demo_OLED_STM32F103RCT6_Software_IIC
===============================================================
fileName fileEncoding
===============================================================
core_cm3.c GB18030
core_cm3.h GB18030
iic.c GB18030
iic.h GB18030
bmp.h GB18030
oled.c GB18030
oled.h GB18030
oledfont.h GB18030
RTE_Components.h GB18030
misc.h GB18030
stm32f10x_adc.h GB18030
stm32f10x_bkp.h GB18030
stm32f10x_can.h GB18030
stm32f10x_cec.h GB18030
stm32f10x_crc.h GB18030
stm32f10x_dac.h GB18030
stm32f10x_dbgmcu.h GB18030
stm32f10x_dma.h GB18030
stm32f10x_exti.h GB18030
stm32f10x_flash.h GB18030
stm32f10x_fsmc.h GB18030
stm32f10x_gpio.h GB18030
stm32f10x_i2c.h GB18030
stm32f10x_iwdg.h GB18030
stm32f10x_pwr.h GB18030
stm32f10x_rcc.h GB18030
stm32f10x_rtc.h GB18030
stm32f10x_sdio.h GB18030
stm32f10x_spi.h GB18030
stm32f10x_tim.h GB18030
stm32f10x_usart.h GB18030
stm32f10x_wwdg.h GB18030
misc.c GB18030
stm32f10x_adc.c GB18030
stm32f10x_bkp.c GB18030
stm32f10x_can.c GB18030
stm32f10x_cec.c GB18030
stm32f10x_crc.c GB18030
stm32f10x_dac.c GB18030
stm32f10x_dbgmcu.c GB18030
stm32f10x_dma.c GB18030
stm32f10x_exti.c GB18030
stm32f10x_flash.c GB18030
stm32f10x_fsmc.c GB18030
stm32f10x_gpio.c GB18030
stm32f10x_i2c.c GB18030
stm32f10x_iwdg.c GB18030
stm32f10x_pwr.c GB18030
stm32f10x_rcc.c GB18030
stm32f10x_rtc.c GB18030
stm32f10x_sdio.c GB18030
stm32f10x_spi.c GB18030
stm32f10x_tim.c GB18030
stm32f10x_usart.c GB18030
stm32f10x_wwdg.c GB18030
delay.c GB18030
delay.h GB18030
sys.c GB18030
sys.h GB18030
gui.c GB18030
gui.h GB18030
main.c GB18030
stm32f10x.h GB18030
stm32f10x_conf.h GB18030
stm32f10x_it.c GB18030
stm32f10x_it.h GB18030
system_stm32f10x.c GB18030
system_stm32f10x.h GB18030
test.c GB18030
test.h GB18030
---------错误统计------------
共0个错误!
-----------------------------

直接打开,舒服了
代码
1 | import os |
- 标题: 批量转换文件编码gb2312转utf-8
- 作者: 康师傅
- 创建于 : 2022-08-10 17:32:11
- 更新于 : 2022-08-10 21:18:38
- 链接: https://blog.ksfu.top/posts/2d8a/
- 版权声明: 本文章采用 CC BY-NC-SA 4.0 进行许可。
评论