class Robots
{
    static ini:=A_ScriptDir "\rules.ini", RulesArray, RulesMode, DefaultMode,
	init()
    {
		If !FileExist(This.ini)
        {
			IniWrite default,rules.ini,设置,默认模式
			IniWrite *.doc;*.docx;*.wps|移动|D:\归类\Word,rules.ini,default,Doc
			IniWrite *.xls;*.xlsx|移动|D:\归类\Excel,rules.ini,default,Xls
			IniWrite *.txt|移动|D:\归类\文本,rules.ini,default,文本
			IniWrite *.pdf|移动|D:\归类\pdf,rules.ini,default,Pdf
			IniWrite *.dwg|移动|D:\归类\CAD,rules.ini,default,CAD
			IniWrite 333*|移动|D:\归类\文件夹,rules.ini,default,333
			IniWrite *c44|移动|D:\归类\文件夹,rules.ini,default,c44
			IniWrite *.zip;*.7z|移动|D:\归类\压缩文件,rules.ini,default,压缩文件
			IniWrite *.pptx;*.ppt|移动|D:\归类\ppt,rules.ini,default,ppt
			IniWrite *.ahk|移动|D:\归类\ahk,rules.ini,default,ahk
            IniWrite C:\Users\Public\Documents|default,rules.ini,autoit,整理文档
            IniWrite C:\Users\Administrator\Desktop|default,rules.ini,autoit,整理桌面
		}
		This.RulesArray:=This.ReadINIToArray(This.ini)
		IniRead, DefaultMode, %INI%, 设置, 默认模式, default
		This.DefaultMode:=DefaultMode
        Return,This
	}
	RButtonDown()
    {
        Global R_Name:="" , R_Rule:="" , R_Action:="" , R_Target:="" , S_Name , Autoit_source , R_Mode
		Menu, Menu_Robot, Add
		Menu, Menu_Robot, DeleteAll
		Menu, Menu_Robot, Add ,ROBOT,RobotMenu
		Menu, Menu_Robot, Add 
		Menu, Menu_Robot, Disable, ROBOT
		Try Menu, KyMenu_New, DeleteAll
		RulesMode:=This.RulesMode
		DefaultMode:=This.DefaultMode
        RulesArray:=This.RulesArray
		INI:=This.INI
        ;MsgBox,% INI
		loop % RulesMode.Length()
		{
			TemItem:=RulesMode[A_Index]
			Menu, KyMenu_New, Add, %TemItem%, MenuHandle_Checked
		}
		Menu, KyMenu_New, Add ; 分隔符
		Menu, KyMenu_New, Add, 打开目标文件夹, Label_OpenSingleDir
        ;MsgBox,% RulesArray.MaxIndex()
		loop % RulesArray.MaxIndex()
		{
			aObj:=RulesArray[A_index]
			Mode_Name:=aObj.name
			if (Mode_Name!=DefaultMode)
				continue
			Mode_Item:=aObj.Rules
            ;MsgBox,% Mode_Item.MaxIndex()
			loop,% Mode_Item.MaxIndex()
			{
				bObj:=Mode_Item[A_Index]
				Item_Target:=bObj[4]
                ;MsgBox,% Item_Target
				Menu, KyMenu_Sub, Add, %Item_Target%,Label_OpenSingleDir
			}
		}
		If (Mode_Item.Length())
			Menu, KyMenu_New, Add, 打开目标文件夹,:KyMenu_Sub

		Menu, KyMenu_New, Add ; 分隔符
		Menu, KyMenu_New, Check, %DefaultMode%
		
		Try Menu, KyMenu_Autoit, DeleteAll
		mobj:={}
		IniRead, OutputVar, %INI%, Autoit
		loop,parse,% OutputVar,`n,`r
		{
			tarr:=StrSplit(A_LoopField,"=")
			mObj:=StrSplit(tarr[2],"|")
			Menu, KyMenu_Autoit, Add, % tarr[1],Label_Autoit
			Menu, KyMenu_AutoitSub, Add,% mObj[1],Label_OpenSingleDir
		}
		Menu, KyMenu_Autoit, Add ; 分隔符
		If (OutputVar)
        {
			Menu, KyMenu_Autoit, Add, 打开源文件夹,:KyMenu_AutoitSub
		}
		Menu, Menu_Robot, Add, dropit,:KyMenu_New
		Menu, Menu_Robot, Add, Autodropit,:KyMenu_Autoit
		Menu, Menu_Robot, Show
		Return
		RobotMenu:
		Return
		MenuHandle_Checked:
			Robots.DefaultMode:=A_ThisMenuitem, INI:=Robots.INI
			IniWrite %A_ThisMenuitem%,%INI%,设置,默认模式
			Robots.RulesArray:=Robots.ReadINIToArray(INI)
		return
		Label_Autoit:
			FileList:=""
			try
			{
				aObj:=StrSplit(YzIni.Autoit[A_ThisMenuItem],"|")
				Loop,Files,% aObj[1] . "\*.*" ,DF
				{
					ActionFunc(A_LoopFilePath,aObj[2])
				}       
			}
		Return
		Label_OpenSingleDir:
			Try Run %A_ThisMenuItem%
		return

		Manager_ChangeMode:	;{规则管理窗体：模式变动，填充ListView
			Robots.init()
            RulesArray:=Robots.RulesArray
			Gui 3:Default
            Gui,3:ListView,dropitrules
			LV_Delete()
			GuiControlGet,R_Mode,,R_Mode
			loop,% RulesArray.MaxIndex()
			{
				aObj:=RulesArray[A_index]
				Mode_Name:=aObj.name
				Mode_Item:=aObj.Rules
				loop,% Mode_Item.MaxIndex()
				{
					bObj:=Mode_Item[A_Index]
					Item_Name:=bObj[1]
					Item_Rules:=bObj[2]
					Item_Action:=bObj[3]
					Item_Target:=bObj[4]
					if (Mode_Name=R_Mode)
						LV_Add("",Item_Name,Item_Rules,Item_Action,Item_Target)
					;~ msgbox % Mode_Name "--" Item_Name "--" Item_Rules "--" Item_Action "--" Item_Target
				}
			}
		return
				;【规则管理窗体】-------------------------------------------------------------
		Label_DrawGUI_ManagerRules:	;{规则管理窗体：绘制
			RulesMode:=Robots.RulesMode
			loop,% RulesMode.Length()
			{
				if (A_Index=1)
					R_Mode:=RulesMode[1] 
				else
					R_Mode:=R_Mode . "|" . RulesMode[A_Index]
			}
			;~ msgbox % R_Mode
			;Gui 2:Hide
			Gui Manager:Destroy
			Gui Manager:+HwndManager_Hwnd
			Gui Manager:Add, ListView, x5 y5 w470 h235 , 名称|规则|操作|目标
			
			Gui Manager:Add,  Groupbox, x5 y250 w240 h55,模式
			Gui Manager:Add, DropDownList , x15 y272 w150 vR_Mode gManager_ChangeMode ,%R_Mode%
			Gui Manager:Add, Button, x175 y270 w55 h23 gManager_New, &N 新建
			Gui Manager:Add,  Groupbox, x250 y250 w220 h55,规则
			Gui Manager:Add, Button, x260 y270 w55 h23 gManager_Add, &A 添加
			Gui Manager:Add, Button, x330 y270 w55 h23 gManager_Modify, &M 修改
			Gui Manager:Add, Button, x400 y270 w55 h23 gManager_Del, &D 删除
			Gui Manager:Add, Text, x10 y318 , 【特别说明】：在更改模式选择列表前，如有修改均要【保存】！
			Gui Manager:Add, Button, x400 y310 w55 h30 gManager_OK, &K 保存
			Gui Manager:Show, w480 h345, 规则模式
			Gui Manager:Default
			GuiControl, Choose,R_Mode,1
			LV_ModifyCol(1, 100)  
			LV_ModifyCol(2, 100)  
			LV_ModifyCol(3, 50)  
			LV_ModifyCol(4, 200)  
			; OnMessage(0x201, "WM_LBUTTONDOWN2")
			Gosub Manager_ChangeMode
		Return
		Label_Autoit_GUI:
		;【一键整理窗体】-------------------------------------------------------------
			
			Gui AutoitManager:Destroy
			Gui AutoitManager:+HwndAutoitManager_Hwnd
			Gui AutoitManager:Add, ListView, x5 y5 w470 h235 , 名称|源目录|模式
			Gui AutoitManager:Add, Groupbox, x5 y250 w240 h55, 模式
			Gui AutoitManager:Add, button , x15 y272 w150 gManager_modes, &G 模式管理
			Gui AutoitManager:Add, Groupbox, x250 y250 w220 h55, 规则
			Gui AutoitManager:Add, Button, x260 y270 w55 h23 gAutoitManager_Add, &A 添加
			Gui AutoitManager:Add, Button, x330 y270 w55 h23 gAutoitManager_Modify, &M 修改
			Gui AutoitManager:Add, Button, x400 y270 w55 h23 gAutoitManager_Del, &D 删除
			Gui AutoitManager:Add, Text, x10 y318 , 【特别说明】：在更改模式选择列表前，如有修改均要【保存】！
			Gui AutoitManager:Add, Button, x400 y310 w55 h30 gAutoitManager_OK, &K 保存
			Gui AutoitManager:Show, w480 h345, 整理规则
			Gui AutoitManager:Default
			LV_ModifyCol(1, 100)  
			LV_ModifyCol(2, 200)  
			LV_ModifyCol(4, 200)  
			Gosub AutoitManager_ChangeMode
		Return
		Manager_modes:
			Gui AutoitManager:Destroy
			Gosub Label_DrawGUI_ManagerRules
		Return
		AutoitManager_Add:
			CurRow:=""
			S_Name:=""
			Autoit_Source:=""
			Gosub Label_DrawGUI_CreatAutoit
		Return
		AutoitManager_Modify:
			Gui 3:Default
            Gui 3:ListView,robot_listview
			FocusedRowNumber := LV_GetNext(0, "F")  ; 查找焦点行
			CurRow:=FocusedRowNumber
			LV_GetText(S_Name, FocusedRowNumber ,1)
			LV_GetText(Autoit_Source, FocusedRowNumber ,2)
			LV_GetText(R_mode, FocusedRowNumber ,3)
			Gosub Label_DrawGUI_CreatAutoit
		Return
		AutoitManager_Del:
			CurRow:=""
			Gui 3:Default
            Gui 3:ListView,robot_listview
			FocusedRowNumber := LV_GetNext(0, "F")  ; 查找焦点行
			LV_Delete(FocusedRowNumber)
		Return
		AutoitManager_OK:
			Gui 3:Default
            Gui 3:ListView,robot_listview
			GuiControlGet,R_Mode,,R_Mode
            IniDelete,rules.ini,autoit
			Loop % LV_GetCount()
			{  
				LV_GetText(S_Name, A_Index ,1)
				LV_GetText(Autoit_Source, A_Index ,2)
				LV_GetText(R_mode, A_Index ,3)
                IniWrite,% Autoit_Source . "|" . R_mode,rules.ini,autoit,%S_Name%
			} 
			;YzIni:=class_EasyIni("yz.ini")
			MsgBox, 64, 提示, 保存成功
			;Gui AutoitManager:Destroy
		Return

		AutoitManager_ChangeMode:
			Gui 3:Default
            Gui 3:ListView,robot_listview
			LV_Delete()
			;MsgBox,% YzIni.GetKeys("Autoit")
			loop,parse,% YzIni.GetKeys("Autoit"),`n
			{
				aObj:=StrSplit(YzIni.Autoit[A_LoopField],"|")
				LV_Add("",A_LoopField,aObj[1],aObj[2])
			}
		Return

		;【主窗体】--------------------------------------------------------------------
		Label_DrawGUI_Main:	;{主窗体：文件拖动窗体

		Return
				
		ManagerGuiClose:	;{规则管理窗体：关闭
			Reload
		return
		;}

		Manager_New:	;{规则管理窗体：新建模式
			InputBox,MyTemInput,请模式名称,,,200,100
			if ErrorLevel
				return
			if (MyTemInput="")
				return
			Gui 3:Default
			GuiControl, ,R_Mode,%MyTemInput%
			GuiControl, Choose,R_Mode,%MyTemInput%
            Gui 3:Default
            Gui,3:ListView,dropitrules
            LV_Delete()
		return
		;}

		Manager_Add:	;{规则管理窗体：添加规则
			CurRow:=""
			R_Name:=""
			R_Rule:=""
			R_Action:=""
			R_Target:=""
			Gosub Label_DrawGUI_CreatRules
		return
		;}

		Manager_Modify:	;{规则管理窗体：修改规则
			Gui 3:Default
            Gui 3:ListView,dropitrules
			FocusedRowNumber := LV_GetNext(0, "F")  ; 查找焦点行
			CurRow:=FocusedRowNumber
			LV_GetText(R_Name, FocusedRowNumber ,1)
			LV_GetText(R_Rule, FocusedRowNumber ,2)
			LV_GetText(R_Action, FocusedRowNumber ,3)
			LV_GetText(R_Target, FocusedRowNumber ,4)
			Gosub Label_DrawGUI_CreatRules
		return
		;}

		Manager_Del:	;{规则管理窗体：删除规则
			CurRow:=""
			Gui 3:Default
            Gui 3:ListView,dropitrules
			FocusedRowNumber := LV_GetNext(0, "F")  ; 查找焦点行
			LV_Delete(FocusedRowNumber)
		return
		;}

		Manager_OK:	;{规则管理窗体：保存数据
        {
			Gui 3:Default
            Gui 3:ListView,dropitrules
			GuiControlGet,R_Mode,,R_Mode
            INI:=Robots.INI ;类a的静态变量b是模板中永久保存的变量，可以用a.b在脚本任何地方调用和修改。c:=new a 之后，c就是a模板的一个复制品，它内部把静态变量复制到c的独立变量中this.b:=a.b，之后你使用的c.b都是独立的，不会改变模板中的静态变量。以前线程需要标签，现在线程可以直接使用函数。函数是被调用，线程是触发。我要纠正一下，c:=new a 之后，没有马上复制静态变量到独立变量。如果c中从来没有赋值c.b或者this.b，则使用模板中的静态变量的值，如果c.b:=1，或者this.b:=1已经赋值了，则与模板变量脱钩了，不再继承值，而是使用独立的内部变量this.b
			IniDelete,%INI%,%R_Mode%
			Loop % LV_GetCount()
			{
				LV_GetText(R_Name, A_Index ,1)
				LV_GetText(R_Rule, A_Index ,2)
				LV_GetText(R_Action, A_Index ,3)
				LV_GetText(R_Target, A_Index ,4)
				IniWrite,%R_Rule%|%R_Action%|%R_Target%,%INI%,%R_Mode%,%R_Name%
			}
			RulesArray:=Robots.ReadINIToArray(INI)
			MsgBox, 64, 提示, 保存成功
        }
		return
		;}

		;}
		;【规则创建窗体】-------------------------------------------------------------
		Label_DrawGUI_CreatAutoit:	;{创建规则窗体：绘制
			loop,% RulesMode.Length()
			{
				if (A_Index=1)
					R_Mode:=RulesMode[1] 
				else
					R_Mode:=R_Mode . "|" . RulesMode[A_Index]
			}
			Gui AutoitCreat:Destroy
			Gui AutoitCreat:Add, Text, x10 y10 w100 h17 +0x200, 1、名称：
			Gui AutoitCreat:Add, Edit, x10 y30 w450 h21 vS_Name,%S_Name%
			Gui AutoitCreat:Add, Text, x10 y60 w100 h17 +0x200, 2、源文件夹：
			Gui AutoitCreat:Add, Edit, x10 y80 w400 h21 vAutoit_source,%Autoit_source%
			Gui AutoitCreat:Add, Button, x415 y78 w45 h23 gAutoitCreat_Brown, 浏览
			Gui AutoitCreat:Add, Text, x10 y110 w100 h17 +0x200, 3、模式：
			Gui AutoitCreat:Add, DropDownList, x10 y130 w450 vR_Mode, %R_Mode%
			Gui AutoitCreat:Add, Button, x130 y225 w70 h30 gAutoitCreat_Save, &O 确定
			Gui AutoitCreat:Add, Button, x270 y225 w70 h30 gAutoitCreat_Cancel, &C 取消
			Gui AutoitCreat:Show, w470 h270, 新建一键整理
			Gui AutoitCreat:Default
			GuiControl, Choose,R_Mode,%R_Mode%
		Return
		AutoitCreat_Save:
			gui,AutoitCreat:Submit
			Gui 3:Default
            Gui 3:ListView,robot_listview
			if (CurRow="")
            {
				LV_Add("",S_Name,Autoit_source,R_Mode)
			} 
            else 
            {
				LV_Modify(CurRow,,R_Name,R_Rule,R_Action,R_Target)
				CurRow:=""
			}	
			Gui AutoitCreat:Destroy
		Return
		AutoitCreat_Cancel:
			Gui AutoitCreat:Destroy
		Return
		;【规则创建窗体】-------------------------------------------------------------
		Label_DrawGUI_CreatRules:	;{创建规则窗体：绘制
			if (R_Action="")
				R_Action:="移动"
			Gui Creat:Destroy
			Gui Creat:Add, Text, x10 y10 w100 h17 +0x200, 1、名称：
			Gui Creat:Add, Edit, x10 y30 w450 h21 vR_Name,%R_Name%
			Gui Creat:Add, Text, x10 y60 w100 h17 +0x200, 2、规则：
			Gui Creat:Add, Edit, x10 y80 w400 h21 vR_Rule,%R_Rule%
			Gui Creat:Add, Button, x415 y78 w45 h23 gCreat_Help, 说明
			Gui Creat:Add, Text, x10 y110 w100 h17 +0x200, 3、操作：
			Gui Creat:Add, DropDownList, x10 y130 w450 vR_Action, 移动||复制
			Gui Creat:Add, Text, x10 y160 w100 h17 +0x200, 4、目标文件夹：
			Gui Creat:Add, Edit, x10 y180 w400 h21 vR_Target,%R_Target%
			Gui Creat:Add, Button, x415 y178 w45 h23 gCreat_Brown, 浏览
			Gui Creat:Add, Button, x130 y225 w70 h30 gCreat_Save, &O 确定
			Gui Creat:Add, Button, x270 y225 w70 h30 gCreat_Cancel, &C 取消
			Gui Creat:Show, w470 h270, 新建规则
			Gui Creat:Default
			GuiControl, Choose,R_Action,%R_Action%
			;OnMessage(0x201, "WM_LBUTTONDOWN2")
		Return
		;}

		Creat_Save:	;{创建规则窗体：保存规则
            gui,Creat:Submit
			Gui 3:Default
            Gui,3:ListView,dropitrules
            ;tempname:=R_Name
            ;MsgBox,% tempname
			if (CurRow="")
            {
				LV_Add("",R_Name,R_Rule,R_Action,R_Target)
			} 
            else 
            {
				LV_Modify(CurRow,,R_Name,R_Rule,R_Action,R_Target)
				CurRow:=""
			}	
			Gui Creat:Destroy
		return
		;}

		Creat_Cancel:	;{创建规则窗体：取消
			Gui Creat:Destroy
		return
		;}

		Creat_Help:	;{创建规则窗体：说明
			MsgBox, 0, 规则说明, 【重要说明】：匹配规则上到下，匹配后则跳过下面条件！！！`n--------------------------------------------------------`n【1】匹配后缀名，如*.jpg`;*.pdf，以中文或英文的分号分开；`n【2】匹配文件名：abc*，匹配以abc开头的文件，不区分后缀名；`n【3】匹配文件名：*abc，匹配以abc结尾的文件，不区分后缀名；`n【4】匹配文件名：*abc*，匹配以包含abc的文件，不区分后缀名；
		return
		;}

		Creat_Brown:	;{创建规则窗体：浏览
			;选择目录
			FileSelectFolder, MySelPath, ::{20d04fe0-3aea-1069-a2d8-08002b30309d}, 3,选择目录
			if ErrorLevel
				return
			if MySelPath =
				return
			Gui Creat:Default
			GuiControl,,R_Target,%MySelPath%
		return

		AutoitCreat_Brown:	;{创建规则窗体：浏览
			;选择目录

			FileSelectFolder, MySouPath, ::{20d04fe0-3aea-1069-a2d8-08002b30309d}, 3,选择目录
			if ErrorLevel
				return
			if MySouPath =
				return
			Gui AutoitCreat:Default

			GuiControl,,Autoit_source,%MySouPath%
		return

		Label_OpenDir:	;{打开默认模式下所有目标文件夹
			loop,% RulesArray.MaxIndex()
			{
				aObj:=RulesArray[A_index]
				Mode_Name:=aObj.name
				if (Mode_Name!=DefaultMode)
					continue
				Mode_Item:=aObj.Rules
				loop,% Mode_Item.MaxIndex()
				{
					bObj:=Mode_Item[A_Index]
					Item_Target:=bObj[4]
					try
						run,%Item_Target%
				}
			}
		return
	}
	ReadINIToArray(INI){
		TemArray:={}
		IniRead,OutModes,%INI%
		This.RulesMode:=[]
		Loop,parse,OutModes,`n,`r
		{
			if (A_LoopField="Autoit") or (A_LoopField="设置")
				continue
			CurMode:=A_LoopField
			This.RulesMode.push(CurMode)
			NewMode:={}
			IniRead,OutRules,%INI%,%CurMode%
			Loop,parse,OutRules,`n
			{
				if (A_LoopField="")
					continue
				CurRule:=RegExReplace(A_LoopField,"=.*?$")  	 ;用户自定义变量的key
				OutRules:=RegExReplace(A_LoopField,"^.*?=") 		 ;用户自定义变量的value
				if OutRules=
					continue
				RuleItem:=StrSplit(OutRules,"|")
				Item_Name:=CurRule
				Item_Rules:=RuleItem[1]
				Item_Action:=RuleItem[2]
				Item_Target:=RuleItem[3]
				TemRule:=[Item_Name,Item_Rules,Item_Action,Item_Target]
				NewMode.push(TemRule)
			}
			TemArray[A_index]:={"Name":CurMode,"Rules":NewMode}
		}
		return TemArray
	}
}
;添加主窗体右键事件
2GuiContextMenu:	;{主窗体：鼠标右键
     If !robot
         Return
	Robots.RButtonDown()
return

2GuiDropFiles:	;{主窗体：拖动文件到主窗体
    If !robot
        Return
	;如果有参数传入，则直接处理，否则弹出窗体
	if 0 > 0
	{
		MySel=%1%
		MyMode=%2%
		MySel:=StrReplace(MySel,";","`n")
	}
    else 
    {
		MySel=%A_GuiEvent%
		MyMode=%DefaultMode%
	}
    ;msgbox % MySel
	;无处理模式，使用默认模式
	ActionFunc(MySel,MyMode)
	if 0 > 0
	{
		ExitApp
	}
    else 
    {      
		Gui,2:Show
        Sleep,500
        TrayTip, , 整理完毕, 5, 17
	}	
return

ActionFunc(MySel,MyMode){
    if (MyMode="")
		MyMode:=Robots.DefaultMode
	RulesArray:=Robots.RulesArray
	Loop,parse,MySel,`n,`r
	{
		if (A_LoopField="")
			continue
		If InStr(FileExist(A_LoopField), "D") { ;区分是否文件夹,Attrib= D ,则是文件夹
			MyOutNameNoExt:=substr(A_LoopField,instr(A_LoopField,"\",,0,1)+1)
			;~ msgbox % MyOutNameNoExt
			loop,% RulesArray.MaxIndex()
			{
				aObj:=RulesArray[A_index]
				Mode_Name:=aObj.name
				if (Mode_Name!=MyMode)
					continue
				Mode_Item:=aObj.Rules
				loop,% Mode_Item.MaxIndex()
				{
					bObj:=Mode_Item[A_Index]
					Item_Name:=bObj[1]
					Item_Rules:=bObj[2]
					Item_Action:=bObj[3]
					Item_Target:=bObj[4]
					;处理规则
					if(instr(Item_Rules,".")>0)
						continue
					TemStr:=StrReplace(Item_Rules,"*","")
                    
					if(substr(Item_Rules,0)="*" and substr(Item_Rules,1,1)!="*")	{
						;【2】匹配文件名；以abc*开头
						if(instr(MyOutNameNoExt,TemStr)=1 ){
							ifnotexist,%Item_Target%
								FileCreateDir,%Item_Target%
							if(Item_Action="复制"){
								FileCopyDir,%A_LoopField%,%Item_Target%\%MyOutNameNoExt%
							} else if (Item_Action="移动") {
								FileMoveDir,%A_LoopField%,%Item_Target%\%MyOutNameNoExt%
							} else {
								
							}

						}
					}else if (substr(Item_Rules,1,1)="*" and substr(Item_Rules,0)!="*")	{
						;【3】匹配文件名；以*abc结尾
						if(instr(MyOutNameNoExt,TemStr)=strlen(MyOutNameNoExt)-strlen(TemStr)+1){
							ifnotexist,%Item_Target%
								FileCreateDir,%Item_Target%
							if(Item_Action="复制"){
								FileCopyDir,%A_LoopField%,%Item_Target%\%MyOutNameNoExt%
							} else if (Item_Action="移动") {
								FileMoveDir,%A_LoopField%,%Item_Target%\%MyOutNameNoExt%
							} else {
								
							}
						}
					}else if (substr(Item_Rules,0)="*" and substr(Item_Rules,1,1)="*")	{
						;【4】匹配文件名；包*abc*含
						if(instr(MyOutNameNoExt,TemStr)>=1 ){
							ifnotexist,%Item_Target%
								FileCreateDir,%Item_Target%
							if(Item_Action="复制"){
								FileCopyDir,%A_LoopField%,%Item_Target%\%MyOutNameNoExt%
							} else if (Item_Action="移动") {
								FileMoveDir,%A_LoopField%,%Item_Target%\%MyOutNameNoExt%
							} else {
								
							}
						}
					}else{
						
					}
				}
			}
		} else {
			SplitPath,A_LoopField,MyOutFileName,MyOutDir,MyOutExt,MyOutNameNoExt,MyOutDrive
			loop,% RulesArray.MaxIndex()
			{
				aObj:=RulesArray[A_index]
				Mode_Name:=aObj.name
				if (Mode_Name!=MyMode)
					continue
				Mode_Item:=aObj.Rules
				loop,% Mode_Item.MaxIndex()
				{
					bObj:=Mode_Item[A_Index]
					Item_Name:=bObj[1]
					Item_Rules:=bObj[2]
					Item_Action:=bObj[3]
					Item_Target:=bObj[4]
					
					;处理规则
					if(instr(Item_Rules,".")>0){	
						;【1】匹配后缀名
						if(instr(Item_Rules,MyOutExt)>0){
							ifnotexist,%Item_Target%
								FileCreateDir,%Item_Target%
							if(Item_Action="复制"){
								filecopy,%A_LoopField%,%Item_Target%
							} else if (Item_Action="移动") {
								filemove,%A_LoopField%,%Item_Target%
							} else {
								
							}
						}
					} else {
						TemStr:=StrReplace(Item_Rules,"*","")
						if(substr(Item_Rules,0)="*" and substr(Item_Rules,1,1)!="*")	{
							;【2】匹配文件名；以abc*开头
							if(instr(MyOutNameNoExt,TemStr)=1 ){
								ifnotexist,%Item_Target%
									FileCreateDir,%Item_Target%
								if(Item_Action="复制"){
									filecopy,%A_LoopField%,%Item_Target%
								} else if (Item_Action="移动") {
									filemove,%A_LoopField%,%Item_Target%
								} else {
									
								}
							}
						}else if (substr(Item_Rules,1,1)="*" and substr(Item_Rules,0)!="*")	{
							;【3】匹配文件名；以*abc结尾
							if(instr(MyOutNameNoExt,TemStr)=strlen(MyOutNameNoExt)-strlen(TemStr)+1){
								ifnotexist,%Item_Target%
									FileCreateDir,%Item_Target%
								if(Item_Action="复制"){
									filecopy,%A_LoopField%,%Item_Target%
								} else if (Item_Action="移动") {
									filemove,%A_LoopField%,%Item_Target%
								} else {
									
								}
							}
						}else if (substr(Item_Rules,0)="*" and substr(Item_Rules,1,1)="*")	{
							;【4】匹配文件名；包*abc*含
							if(instr(MyOutNameNoExt,TemStr)>=1 ){
								ifnotexist,%Item_Target%
									FileCreateDir,%Item_Target%
								if(Item_Action="复制"){
									filecopy,%A_LoopField%,%Item_Target%
								} else if (Item_Action="移动") {
									filemove,%A_LoopField%,%Item_Target%
								} else {
									
								}
							}
						}
                        else
                        {
							
						}
					}
				}
			}
            ;MsgBox,% Item_Target
		}
	}
}

WM_LBUTTONDBLCLK(){	;主窗体：左键双击
	; Gosub Label_DrawGUI_ManagerRules
}