Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Example:
- F1::NewFolderFromSelection()
- ; Put in Lib\NewFolderFromSelection.ahk
- NewFolderFromSelection()
- {
- cwd := files := ""
- hWnd := WinActive("A")
- WinGetClass wClass, % "ahk_id" hWnd
- if (wClass = "CabinetWClass") {
- WinGetText wText, A
- RegExMatch(wText, "Address: \K.+", cwd)
- files := NewFolderFromSelection_Folder(hWnd)
- } else if (wClass ~= "Progman|WorkerW") {
- cwd := A_Desktop
- files := NewFolderFromSelection_Desktop(hWnd)
- } else {
- MsgBox 0x40010, Error, Window not supported.
- return
- }
- if (!files.Count())
- return
- InputBox newFolder, New folder name:,,, 200, 100
- if (!newFolder)
- return
- exist := FileExist(cwd "\" newFolder)
- if (exist ~= "D") {
- MsgBox 0x40024, Continue?, The folder already exists`, move files into it?
- IfMsgBox No
- return
- } else if (exist) {
- MsgBox 0x40010, Error, A file with the given name already exists.
- return
- } else {
- FileCreateDir % cwd "\" newFolder
- if (ErrorLevel) {
- MsgBox 0x40010, Error, Folder couldn't be created.
- return
- }
- }
- errors := []
- for _,file in files {
- if (FileExist(file) ~= "D")
- FileMoveDir % file, % cwd "\" newFolder, 1
- else
- FileMove % file, % cwd "\" newFolder
- if (ErrorLevel)
- errors.Push(file)
- }
- total := errors.Count()
- if (total) {
- s := total = 1 ? "" : "s"
- msg := "File" s " couldn't be moved:`n`n"
- loop % total
- msg .= "- " errors[A_Index]
- MsgBox 0x40010, % "Error" s, % msg
- }
- }
- NewFolderFromSelection_Desktop(hWnd)
- {
- ControlGet selection, List, Selected, SysListView321
- files := []
- loop Parse, selection, `n
- files.Push(A_Desktop "\" StrSplit(A_LoopField, "`t")[1])
- return files
- }
- NewFolderFromSelection_Folder(hWnd)
- {
- files := [], selected := {}
- for window in ComObjCreate("Shell.Application").Windows {
- if (hWnd != window.hWnd)
- continue
- selected := window.Document.SelectedItems
- break
- }
- for item in selected
- files.Push(item.Path)
- return files
- }
Add Comment
Please, Sign In to add comment