批量转换编码

/*
作者:    	莫名791046206/iceideal[at]gmail[dot]com
脚本说明:	接受文件夹路径,将该文件夹及其子文件夹下 用户指定后缀 的文本文件转换成指定的编码。并可选择是否备份
范例:    	批量转换格式 = run|Extension批量转换格式.ahk "{file:pathfull}"
功能:		1.可以接受命令行文件夹参数;2.可以手动输入文件夹;
输入:		后缀:可以接受以半角 | 分隔的后缀。如 ini|txt|ahk|ahkl
版本:		v0.2 gui
注意:		不要指定非文本文档的后缀哦。因为 FileAppend 的处理过快,造成loop会重新循环已经处理过的文件,所以将生成的文件暂存在所处理的文件夹的上一层,在处理完后,再统一移动回来。
完成时间:	2013-01-31 10:34:46/2013-02-2 12:13:04
*/
SetBatchLines, -1  ; 让操作以最快速度进行.
#SingleInstance force
;============================================接受参数============================================
pathfull = %1%
;if pathfull =
;{
;	MsgBox, 没用输入参数,请查正
;	Return
;}

setGui:
Gui,New
Gui, font, s14, Verdana 
Gui, Add, Text, x76 y5 w200 h20 , 批量转换格式
Gui, font, s9, Verdana 
Gui, Add, Text, x5 y30 w40 h20 , 文件夹
Gui, Add, Text, x5 y55 w40 h20 , 后缀
Gui, Add, Text, x5 y85 w40 h20 , 编码
Gui, Add, Edit, x50 y30 w140 h20 +ReadOnly vpathfull , %pathfull%
Gui, Add, Button,x190 y27 w80 h25, 选择文件夹..
Gui, Add, Edit, x50 y55 w220 h20 v后缀, ini|txt|ahk|ahkl
Gui, Add, DropDownList, x50 y80 w90 h100 Choose1 v编码, UTF-8|UTF-8-RAW|UTF-16|UTF-16-RAW|ANSI
Gui, Add, Text, x150 y85 w60 h20, 是否备份:
Gui, Add, Radio, x210 y80 w30 h20 v备份 +Checked, 是
Gui, Add, Radio, x240 y80 w30 h20 v备份2 , 否
Gui, Add, Text, x5 y110 w120 h20, 转换列表存入剪贴板:
Gui, Add, Radio, x125 y105 w30 h20 v存入 +Checked, 是
Gui, Add, Radio, x155 y105 w30 h20 v存入2 , 否
Gui, Add, Button, x50 y130 w60 h30 +Default, 确定
Gui, Add, Button, x180 y130 w60 h30 , 取消
;Gui, Color, 000
;Gui +LastFound  ; 让 GUI 窗口成为 上次找到的窗口 以用于下一行的命令.
;WinSet, TransColor, EEAA99 180
Gui, Show, h162 w275, 批量转换格式
GuiControl,Disable , 选择文件夹
if pathfull = 
{
	GuiControl,Enable , 选择文件夹
	GuiControl,-ReadOnly , pathfull
}
Return

Button选择文件夹..:
FileSelectFolder, SelectFolder, , 3
if SelectFolder =
{
    ;MsgBox, You didn't select a folder.
}else{
	GuiControl,,pathfull,%SelectFolder%
}
Return

Button确定:
Gui, Submit

if(pathfull = )
{
	MsgBox,文件夹为空,程序将退出!
	Gosub, GuiClose
}
IfnotExist, %pathfull%
{
	MsgBox,文件夹不存在,程序将退出!
	Gosub, GuiClose
}
if 备份 = 0
{
	MsgBox, 308, 提示, 你没有选择备份文件,这很危险!`n`n点击  是 ,就不备份就不备份`n`n点击  否 ,将设置备份并进行转换?
	ifMsgBox, No
	{
		备份 = 1
	}
}
if(!RegExMatch(编码,"i)^(UTF-8|UTF-16|UTF-8-RAW|UTF-16-RAW|ANSI)$")){
	Encoding = UTF-8
}
if(编码 = ANSI){
	Encoding = 
}
;============================================设置,临时文件夹处理============================================
转换列表 =
转换个数=0
SplitPath, pathfull, OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive
;上一层文件夹为 OutDir
临时文件夹名字 := OutDir . "~转换格式临时文件夹" . A_Now
FileCreateDir, %临时文件夹名字%
;============================================转换============================================

Loop, parse, 后缀, |
{
    ;MsgBox, 后缀 number %A_Index% is %A_LoopField%.
	转换列表%A_LoopField% = 
	转换个数%A_LoopField% = 0
	Loop,%pathfull%*.%A_LoopField%,0,1
	{
		fileContent =
		FileRead,fileContent,%A_LoopFileLongPath%
		if 备份 = 1
		{
			FileMove, %A_LoopFileLongPath%, %A_LoopFileLongPath%.bak ,1
		}Else{
			FileDelete, %A_LoopFileLongPath%
		}
		;在临时文件夹中建立子文件夹
		StringReplace, f_A_LoopFileLongPath, A_LoopFileLongPath, %pathfull%, %临时文件夹名字%
		SplitPath, f_A_LoopFileLongPath, , f_OutDir
		IfNotExist, %f_OutDir%
		{
			FileCreateDir, %f_OutDir%
		}
		FileAppend,%fileContent%,%f_A_LoopFileLongPath%,%Encoding%
		转换列表%A_LoopField% .= A_LoopFileLongPath . "`n"
		转换个数%A_LoopField% ++
	}
}
FileMoveDir,%临时文件夹名字%,%pathfull%,2
;============================================转换后处理============================================
转换列表_head := 
Loop, parse, 后缀, |
{
	转换列表_head .= A_LoopField . " :" . 转换个数%A_LoopField% . "个`n"
	if 转换个数%A_LoopField% > 0
	{
		转换列表 .= 转换列表%A_LoopField%
	}
	转换个数 += 转换个数%A_LoopField%
}
if 存入 = 1
{
	Clipboard := 转换列表
	ClipWait
}

TrayTip,转换完成,成功转换了以下 %转换个数% 个文件`n%转换列表_head%%转换列表%
Sleep, 3000
TrayTip
Gosub, GuiClose
Return

Esc::
Button取消:
GuiClose:
ExitApp

给TA捐赠
共{{data.count}}人
人已捐赠
其他

批量查询

2020-3-9 2:50:44

其他

拖放msi文件到本脚本读取其基本信息

2020-3-9 2:52:44

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索