anonymous1184

NewFolderFromSelection.ahk

Jan 30th, 2022 (edited)
1,072
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Example:
  2. ; F1::NewFolderFromSelection()
  3.  
  4. ; Put in Lib\NewFolderFromSelection.ahk
  5.  
  6. NewFolderFromSelection()
  7. {
  8.     cwd := files := ""
  9.     hWnd := WinActive("A")
  10.     WinGetClass wClass, % "ahk_id" hWnd
  11.     if (wClass = "CabinetWClass") {
  12.         WinGetText wText, A
  13.         RegExMatch(wText, "Address: \K.+", cwd)
  14.         files := NewFolderFromSelection_Folder(hWnd)
  15.     } else if (wClass = "WorkerW") {
  16.         cwd := A_Desktop
  17.         files := NewFolderFromSelection_Desktop(hWnd)
  18.     }
  19.     if !files.Count()
  20.         return
  21.     InputBox newFolder, New folder name:,,, 200, 100
  22.     if (!newFolder)
  23.         return
  24.     FileCreateDir % cwd "\" newFolder
  25.     for _,file in files
  26.         FileMove % file, % cwd "\" newFolder
  27. }
  28.  
  29. NewFolderFromSelection_Desktop(hWnd)
  30. {
  31.     ControlGet selection, List, Selected, SysListView321
  32.     files := []
  33.     loop Parse, selection, `n
  34.         files.Push(A_Desktop "\" StrSplit(A_LoopField, "`t")[1])
  35.     return files
  36. }
  37.  
  38. NewFolderFromSelection_Folder(hWnd)
  39. {
  40.     selected := ""
  41.     for window in ComObjCreate("Shell.Application").Windows {
  42.         if (hWnd != window.hWnd)
  43.             continue
  44.         selected := window.Document.SelectedItems
  45.         break
  46.     }
  47.     if (!selected)
  48.         return
  49.     files := []
  50.     for item in selected {
  51.         files.Push(item.Path)
  52.     }
  53.     return files
  54. }
  55.  
Add Comment
Please, Sign In to add comment