xCopyPlus带文件夹结构批量复制某类文件

;作者:sunwind
;2015年10月27日22:34:33
;功能:
;xcopy的增强版,可以过滤扩展名 
;xCopyPlus批量复制某类文件

Gui,+AlwaysOnTop
Gui, Add, Text,,源路径(拖放或输入源目录,多条请换行)
Gui, Add, Edit, vSourceEdit  W300 R2
Gui, Add, Text,,目的路径(拖放或输入目的目录,只支持一条)
Gui, Add, Edit, vDestinationEdit  W300 R2
Gui, Add, Text,,文件类型(多个类型请用|符号分割))
Gui, Add, Edit, vFileType  W300,rar|zip
Gui,Add,Button,gFilterCopy,复制文件
Gui,Add,Button,gStructureCopy,仅复制文件夹结构
Options:="W520 H240"
Title:="带文件夹结构复制某类型文件"

Gui, Show , %Options%, %Title%
return
GuiDropFiles:  ; 对拖放提供支持.

 SelectedFileName := A_GuiEvent

;获取鼠标下面的控件
MouseGetPos, , , id, control
;~ WinGetTitle, title, ahk_id %id%
WinGetClass, class, ahk_id %id%
;~ ToolTip, ahk_id %id%`nahk_class %class%`n%title%`nControl: %control%

if (control="Edit1")
{
	GuiControl,, SourceEdit, %SelectedFileName%  ; 在控件中显示文本.
}
if (control="Edit2")
{
	GuiControl,, DestinationEdit, %SelectedFileName%  ; 在控件中显示文本.
}
return

FilterCopy:
Gui,-AlwaysOnTop
ControlGetText,SourcePath,Edit1
ControlGetText,DestinationPath,Edit2
ControlGetText,myext,Edit3
tar_ext=i).(%myext%)$    ;定义你的文件类型
;~ 只能拖动文件夹到路径和目的路径
;~ 源路径支持同时拖入多个文件夹、目的路径只支持一个
response:=
Loop, parse, SourcePath, `n, `r  ; 在 `r 之前指定 `n, 这样可以同时支持对 Windows 和 Unix 文件的解析.
{
    SourceFolder:=Trim(A_LoopField, OmitChars ="`n")
	SourceFolder :=   RTrim(SourceFolder,"")
	DestinationFolder :=   RTrim(DestinationPath,"") ;remove a trailing backslash, if present
	
	if not InStr(FileExist(SourceFolder), "D")
		{
			MsgBox 不存在源路径
		}
		
	if  not InStr(FileExist(DestinationFolder), "D")
		{
			FileCreateDir,%DestinationFolder%
			MsgBox 创建了【%DestinationFolder%】目录
		}
		
		response .= FilterCopy(SourceFolder,DestinationFolder,tar_ext)  . "`n"

}
MsgBox %myext%文件复制完成!`n%response%
Run %DestinationFolder%
return



StructureCopy:
Gui,-AlwaysOnTop
ControlGetText,SourcePath,Edit1
ControlGetText,DestinationPath,Edit2

DestinationFolder :=   RTrim(DestinationPath,"") ;remove a trailing backslash, if present

if  not InStr(FileExist(DestinationFolder), "D")
	{
		FileCreateDir,%DestinationFolder%
	}

arr:=StrSplit(SourcePath,"`r`n")
res:=
for key,SourcePath in arr
{
	SourceFolder :=   RTrim(SourcePath,"")
	if not InStr(FileExist(SourceFolder), "D")
		{
			MsgBox 不存在源路径
		}

	res.=StructureCopy(SourceFolder,DestinationFolder)
}
MsgBox  文件夹结构复制完成`n%res% ;输出结果
Run %DestinationFolder%
return



Escape:
GuiClose:  ; 用户关闭了窗口.
ExitApp

StructureCopy(fromdir,todir)
{
	t:=
	Loop,%fromdir%*.*,2,1  ;2只是文件夹
	{
		t.=A_LoopFileFullPath . "`n"
		SplitPath,fromdir,,fatherDir
		StringReplace,DirName,A_LoopFileFullPath,%fatherDir%,%todir%,all
		FileCreateDir, %DirName% 
	}
StringReplace,out,t,%fatherDir%,%todir%,all
return %out%
}

FilterCopy(fromdir,todir,tar_ext)
{
	StructureCopy(fromdir,todir)
	t:=
	Loop,%fromdir%*.*,1,1 ; 第一个参数1获取所有匹配通配符模式的文件和文件夹. 
	{
		If (! RegExMatch(A_LoopFileFullPath, tar_ext))  ;在此过滤
			continue
		t.=A_LoopFileFullPath . "`n"
		SplitPath,fromdir,,fatherDir
		StringReplace,DirName,A_LoopFileFullPath,%fatherDir%,%todir%,all
		FileCopy,%A_LoopFileFullPath%,%DirName%
		;~ ErrorCount += ErrorLevel
       ;~ if ErrorLevel  ; Report each problem folder by name.
           ;~ MsgBox Could not copy %A_LoopFileFullPath% into %DestinationFolder%.
	}
StringReplace,out,t,%fatherDir%,%todir%,all
;~ return ErrorCount
return %out%
}


;~ CopyFilesAndFolders(SourcePattern, DestinationFolder, DoOverwrite = false)
; Copies all files and folders matching SourcePattern into the folder named DestinationFolder and
; returns the number of files/folders that could not be copied.

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

xCopyPlus带文件夹结构批量复制某类文件 (2)

2020-3-8 23:44:44

其他

youdao翻译_by_sunwind_La_Lw(需先配置20行及21行)

2020-3-9 0:18:44

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