[办公]用ahk写的一个桌面整理软件

有的人可能喜欢把临时文件放在桌面,这里制作了一个简陋的桌面整理工具。因为贴在桌面这个功能和桌面的类名有关联,非win10用户可能出现bug,导致脚本不能贴在桌面上,需要自己修改一下。

有的人可能喜欢把临时文件放在桌面,这里制作了一个简陋的桌面整理工具。因为贴在桌面这个功能和桌面的类名有关联,非win10用户可能出现bug,导致脚本不能贴在桌面上,需要自己修改一下。

一个简陋的桌面整理脚本,https://github.com/fuwt/sdesktop

非win10用户因为桌面的类名不一样,可能出现bug,导致脚本不能贴在桌面上,需要自己修改一下。[办公]用ahk写的一个桌面整理软件

SetWorkingDir %A_Desktop%
 #SingleInstance, Force
 SetWinDelay, -1
 SetControlDelay, -1

; 创建GUI
 x0 := A_ScreenWidth - 435
 WinGet, hDesktop, ID, ahk_class Progman
 ControlGet, hDesktopIcon, Hwnd,, SysListView321, ahk_id %hDesktop%
 Control, Hide, ,,ahk_id %hDesktopIcon%
 BoxW := A_ScreenWidth / 4.5
 BoxH := A_ScreenHeight / 4.5
 Gui, +ToolWindow +LastFound -Caption -DPIScale +Parent%hDesktop%
 Gui, Color, ffeeee
 Gui, Margin, 0, 0
 Gui, Add, Picture, w%BoxW% h%BoxH%, %A_ScriptDir%\img\Background.png
 ; Gui, Add, GroupBox, x0 y+20 w384 r10 cFFFFFF, 常用
Gui, Font, s12
 Gui, Add, ListView, w%BoxW% y+10 vMyListView1 gMySubroutine, 名称|修改时间|路径|EXT
 Gui, Add, ListView, w%BoxW% y+10 vMyListView2 gMySubroutine, 名称|修改时间|路径|EXT
 Gui, Add, ListView, w%BoxW% y+10 vMyListView3 gMySubroutine, 名称|修改时间|路径|EXT
 Gui, Add, ListView, w%BoxW% y+10 vMyListView99 gMySubroutine, 名称|修改时间|路径|EXT
 Gui, Font, s57
 Gui, Add, Text, x10 y50 w364 Center cFFFFFF BackgroundTrans +HwndTimeStr, Time
 Gui, Font, s20
 Gui, Add, Text, x10 y150 w364 Center cFFBBBB BackgroundTrans +HwndDateStr, Time
 WinSet, TransColor, FFEEEE
 WinGetPos,,,,h,ahk_class Shell_TrayWnd
 h := A_ScreenHeight-h
 ; Gui, Show, x0 y0 w%A_ScreenWidth% h%h% NA
 Gui, Show, x%x0% y10
 shell := ComObjCreate("shell.application")
 shell.toggledesktop()
 Menu, Tray, Add, 隐藏桌面图标, hideDeskIcon
 Menu, MyContextMenu, Add, 删除, DeleteFile
 Menu, MyContextMenu, Add, 复制, CopyFile
 Menu, MyContextMenu, Add, 移动, MoveFile
 loop
 {
 IniRead, OutputVar, %A_ScriptDir%\config.ini, common, %A_Index%, 0
 if (OutputVar = 0)
 break
 if (SubStr(OutputVar,0) != "\")
 OutputVar .= "\"
 Name := StrSplit(OutputVar, "|")[1]
 Menu, CopyFile2, Add, %Name%, CopyFile2Common
 Menu, MoveFile2, Add, %Name%, MoveFile2Common
 }
 Menu, MyContextMenu, Add, 复制到常用文件夹, :CopyFile2
 Menu, MyContextMenu, Add, 移动到常用文件夹, :MoveFile2

 

; 生成图标列表
arr := [.xls,.xlsx,.doc,.docx,.ppt,.pptx,.txt,.ahk,.jpg,.png,.pdf,.psd]
 Icons := {}
 ImageListID := IL_Create(50)
 for item in arr
 {
 ext := arr[item]
 RegRead, OutputVar, HKEY_CLASSES_ROOT, %ext%
 RegRead, OutputVar, HKEY_CLASSES_ROOT\%OutputVar%\DefaultIcon
 Icons[SubStr(ext,2)] := A_Index
 img := StrSplit(OutputVar, "`,")
 if !OutputVar
 IL_Add(ImageListID, "shell32.dll", 1)
 else
 IL_Add(ImageListID, img[1], img[2])
 }
 count := 0
 for k,v in Icons
 count++
 Icons["AADIR"] := count + 1
 IL_Add(ImageListID, "shell32.dll", 4)

; 开始
GoSub, hideDeskIcon
 GoSub, SetDate
 GoSub, SetTime
 GoSub, FillGrid
 SetTimer, SetTime, 1000
 SetTimer, SetDate, 1000000
 SetTimer, ReFlush, 1000
 Return

; 标签
SetTime:
 FormatTime, OutputVar, %A_Now%, HH:mm:ss
 GuiControl, Text, %TimeStr%, %OutputVar%
 Return
 SetDate:
 FormatTime, OutputVar, %A_Now%, yyyy/MM/dd ddd
 GuiControl, Text, %DateStr%, %OutputVar%
 Return
 ReFlush:
 if !BacT
 BacT := ModifyT
 FileGetTime, ModifyT, %A_Desktop%
 if ModifyT != %BacT%
 GoSub FillGrid
 BacT := ModifyT
 Return

FillGrid:
 loop 3
 {
 LsN := A_Index
 Gui, ListView, MyListView%LsN%
 GuiControl, -Redraw, MyListView%LsN%
 LV_Delete()
 IniRead, path, %A_ScriptDir%\config.ini, grid%A_Index%, path
 IniRead, exts, %A_ScriptDir%\config.ini, grid%A_Index%, exts
 LV_SetImageList(ImageListID)
 Loop, Files, *.*, DF
 {
 ext := A_LoopFileExt
 if A_LoopFileAttrib contains H,R,S
 continue
 if A_LoopFileAttrib = D
 ext := "AADIR"
 if ext not in %exts%
 continue
 collected .= A_LoopFileName . "`,"
 FormatTime, OutputVar, %A_LoopFileTimeModified%, ShortDate
 LV_Add("icon" . Icons[ext],A_LoopFileName, OutputVar,A_LoopFileLongPath,ext)
 LV_ModifyCol(1,BoxW-120)
 LV_ModifyCol(2)
 LV_ModifyCol(3,0)
 LV_ModifyCol(4,0)
 }
 GuiControl, +Redraw, MyListView%LsN%
 }
 Gui, ListView, MyListView99
 GuiControl, -Redraw, MyListView99
 LV_Delete()
 LV_SetImageList(ImageListID)
 Loop, Files, *.*, DF
 {
 if A_LoopFileAttrib contains H,R,S
 continue
 if A_LoopFileName in %collected%
 continue
 if A_LoopFileAttrib = D
 ext := "AADIR"
 else
 ext := A_LoopFileExt
 FormatTime, OutputVar, %A_LoopFileTimeModified%, ShortDate
 LV_Add("icon" . Icons[ext],A_LoopFileName, OutputVar,A_LoopFileLongPath,ext)
 LV_ModifyCol(1,BoxW-120)
 LV_ModifyCol(2)
 LV_ModifyCol(3,0)
 LV_ModifyCol(4,"0 sort")
 }
 GuiControl, +Redraw, MyListView99
 Return
 MySubroutine:
 if A_GuiEvent = DoubleClick
 {
 Gui, ListView, %A_GuiControl%
 LV_GetText(OutputVar, A_EventInfo, 3)
 run % OutputVar
 }
 Return
 GuiContextMenu:
 ; ToolTip % A_GuiControl . A_EventInfo
 if A_GuiControl contains MyListView
 {
 RClickControl := A_GuiControl
 Menu, MyContextMenu, Show
 }
 return
 showDeskIcon:
 Control, Show, ,,ahk_id %hDesktopIcon%
 Menu, Tray, Add, 隐藏桌面图标, hideDeskIcon
 Menu, Tray, Delete, 显示桌面图标
Return
 hideDeskIcon:
 Control, Hide, ,,ahk_id %hDesktopIcon%
 Menu, Tray, Add, 显示桌面图标, showDeskIcon
 Menu, Tray, Delete, 隐藏桌面图标
Return
 DeleteFile:
 Gui, ListView, %RClickControl%
 guicontrol, -redraw, %RClickControl%
 n := lv_getcount("s")
 loop % n
 {
 RowNumber := lv_getnext()
 LV_GetText(FullPath, RowNumber,3)
 LV_Delete(RowNumber)
 FileRecycle, %FullPath%
 }
 guicontrol, +redraw, %RClickControl%
 Return
 MoveFile:
 Gui, ListView, %RClickControl%
 FileSelectFolder, OutputVar
 guicontrol, -redraw, %RClickControl%
 n := lv_getcount("s")
 loop % n
 {
 RowNumber := lv_getnext()
 LV_GetText(FullPath, RowNumber,3)
 CopyFilesAndFolders(FullPath, OutputVar)
 FileDelete, %FullPath%
 LV_Delete(RowNumber)
 }
 guicontrol, +redraw, %RClickControl%
 Return
 CopyFile:
 Gui, ListView, %RClickControl%
 FileSelectFolder, OutputVar
 guicontrol, -redraw, %RClickControl%
 n := lv_getcount("s")
 loop % n
 {
 RowNumber := lv_getnext(RowNumber)
 LV_GetText(FullPath, RowNumber,3)
 CopyFilesAndFolders(FullPath, OutputVar)
 }
 guicontrol, +redraw, %RClickControl%
 Return
 CopyFile2Common:
 Gui, ListView, %RClickControl%
 guicontrol, -redraw, %RClickControl%
 n := lv_getcount("s")
 DestPattern := StrSplit(A_ThisMenuItem, "|")[2]
 loop % n
 {
 RowNumber := lv_getnext(RowNumber)
 LV_GetText(FullPath, RowNumber,3)
 CopyFilesAndFolders(FullPath, DestPattern)
 MsgBox % FullPath
 }
 guicontrol, +redraw, %RClickControl%
 Return
 MoveFile2Common:
 Gui, ListView, %RClickControl%
 guicontrol, -redraw, %RClickControl%
 n := lv_getcount("s")
 DestPattern := StrSplit(A_ThisMenuItem, "|")[2]
 loop % n
 {
 RowNumber := lv_getnext(RowNumber)
 LV_GetText(FullPath, RowNumber,3)
 CopyFilesAndFolders(FullPath, DestPattern)
 FileDelete, %FullPath%
 LV_Delete(RowNumber)
 }
 guicontrol, +redraw, %RClickControl%
 Return
 CopyFilesAndFolders(SourcePattern, DestinationFolder, DoOverwrite = false)
 {
 ; 首先复制所有文件 (不是文件夹):
FileCopy, %SourcePattern%, %DestinationFolder%, %DoOverwrite%
 ErrorCount := ErrorLevel
 ; 现在复制所有文件夹:
Loop, %SourcePattern%, 2 ; 2 表示 "只获取文件夹".
 {
FileCopyDir, %A_LoopFileFullPath%, %DestinationFolder%\%A_LoopFileName%, %DoOverwrite%
 ErrorCount += ErrorLevel
 if ErrorLevel ; 报告每个出现问题的文件夹名称.
MsgBox Could not copy %A_LoopFileFullPath% into %DestinationFolder%.
 }
 return ErrorCount
 }

 

 

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

[教程][文件]AutoHotKey系列教程中级教程第四节第一课文件操作简介

2017-8-3 20:41:06

其他案例

[办公]简单工作记录

2017-8-7 16:38:59

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
有新私信 私信列表
搜索