Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;context: https://www.reddit.com/r/AutoHotkey/comments/nvdyil/need_help/
- sa:= comobjcreate("shell.application")
- +f12::
- dirname:= "new destination folder name without path"
- wingetclass cn, a
- if (cn == "CabinetWClass") {
- winget hw, id, a
- ws:= sa.windows()
- loop % ws.count {
- wd:= ws.item(a_index - 1)
- if (wd.hwnd == hw) {
- dc:= wd.document
- if (substr(comobjtype(dc, "name"), 1, 12) == "IShellFolder") {
- si:= dc.selecteditems
- if (si.count > 0) {
- sd:= dc.folder
- dir:= sd.self.path
- if (substr(dir, 1, 1) != ":") {
- tp:= dir "\" dirname
- if (fileexist(tp) == "") {
- filecreatedir %tp%
- if (errorlevel != 0) {
- msgbox 16, Copy To New Folder
- , % "Failed to create new folder. " errMsg()
- return
- }
- }
- ig:= false
- loop % si.count {
- it:= si.item(a_index - 1)
- sp:= it.path
- if (instr(fileexist(sp), "D") > 0) {
- filemovedir %sp%, %tp%, 1
- } else {
- filemove %sp%, %tp%, 1
- }
- if ((errorlevel != 0) && !ig) {
- msgbox 19, Copy To New Folder
- , % "Failed to move below file/folder. " errMsg() "`n`n"
- . sp "`n`nDo you want to ignore further errors?"
- ifmsgbox Yes
- ig:= true
- ifmsgbox Cancel
- return
- }
- }
- } else {
- msgbox 16, Copy To New Folder, This is not a file system folder.
- }
- } else {
- msgbox 16, Copy To New Folder, No file/folder is selected.
- }
- }
- return
- }
- }
- }
- return
- errMsg() {
- varsetcapacity(s, 4096)
- dllcall("FormatMessage", int, 0x1000, int, 0, int, a_lasterror, int, 0
- , str, s, int, 4096, str, "")
- return strreplace(s, "`r`n", " ")
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement