用法:选中文件,ctrl+g,自动整理到 D 盘,通过本实例简单改造可以实现各种自动整理功能,自动化办公的人士可以了解一下!购买文章后,免费给与指导!
注意:更换代码中“D:\”为自身目标文件夹
[erphpdown]
^g::this_path := Selected_Files() ; 检测选中的文件Des_path:="D:\"if (this_path)loop, Parse, this_path , `n, `r ; 在 `r 之前指定 `n, 这样可以同时支持对 Windows 和 Unix 文件的解析.{MoveFilesAndFolders(A_LoopField,Des_path) ; 移动文件}elseMsgBox, 没有选中文件!return;移动文件或文件夹MoveFilesAndFolders(SourcePattern, DestinationFolder, DoOverwrite = false); 移动匹配 SourcePattern 的所有文件和文件夹到 DestinationFolder 文件夹中且; 返回无法移动的文件/文件夹的数目.{; 首先移动所有文件 (不是文件夹):FileMove, %SourcePattern%, %DestinationFolder%, %DoOverwrite%ErrorCount := ErrorLevel; 现在移动所有文件夹:loop, %SourcePattern%, 2 ; 2 表示 "只获取文件夹".{FileMoveDir, %A_LoopFileFullPath%, %DestinationFolder%\%A_LoopFileName%, %DoOverwrite%ErrorCount += ErrorLevelif ErrorLevel ; 报告每个出现问题的文件夹名称.MsgBox, 文件夹%A_LoopFileFullPath% 不能移动至%DestinationFolder%.}return ErrorCount};检查是否选中文件Selected_Files(){;我的电脑句柄IfWinActive, ahk_class CabinetWClass{for window in ComObjCreate("Shell.Application").Windowsif window.HWND = WinExist("A")this_window := window; 如果多个项目被选中if(this_window.Document.SelectedItems.Count > 1){these_files := ""for item in this_window.Document.SelectedItemsthese_files .= item.Path . "`n"return these_files}elsereturn this_window.Document.FocusedItem.Path}; 桌面句柄if(WinActive("ahk_class Progman") || WinActive("ahk_class WorkerW")){ControlGet, selectedFiles, List, Selected Col1, SysListView321, A; 如果多个项目被选中if InStr(selectedFiles, "`n"){these_files := ""loop, Parse, selectedFiles, `n, `rthese_files .= A_Desktop . "\" . A_LoopField . "`n"return these_files}elsereturn A_Desktop . "\" . selectedFiles}elsereturn false}
[/erphpdown]
https://www.autoahk.com/archives/9210
