ExtractFolder - Move contents of a folder out
Posted: 26 Apr 2024, 04:21
How to use:
1. Run the script as admin to add an option for folder context menu
2. Right click on a folder and choose Extract
1. Run the script as admin to add an option for folder context menu
2. Right click on a folder and choose Extract
Code: Select all
#Requires Autohotkey v2.0
#SingleInstance Off
SetWorkingDir A_ScriptDir ; Ensures a consistent starting directory.
#NoTrayIcon
; register without args
if(A_Args.length <= 0){
; Need to be admin
if(!A_IsAdmin){
r := msgbox("Register contextmenu?", "Register", "OKCancel Icon?")
if(r == "OK"){
Run '*RunAs "' . A_AhkPath . '" "' . A_ScriptFullPath '"'
}
}
regValue := '"' . A_AhkPath . '" "' . A_ScriptFullPath . '" "%1"'
regPath := "HKEY_CLASSES_ROOT\Directory\shell\Extract"
try {
RegWrite("Extract!(&X)", "REG_SZ", regPath)
RegWrite(regValue, "REG_SZ", regPath . "\command")
msgbox "Added`n" . regValue . "`n`nTo " . regPath
} catch as err {
msgbox err.message
}
} else {
; Extract!
; msgbox "args len: " . A_Args.length . "`n`nargs1: " . A_Args[1] ;debug
srcFolder := A_Args[1]
targetFolder := substr(srcFolder, 1, instr(srcFolder, '\',, -1) - 1)
comobject('shell.application').namespace(targetFolder).movehere(srcFolder '\*')
}