Page 1 of 1

ExtractFolder - Move contents of a folder out

Posted: 26 Apr 2024, 04:21
by byzod
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

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 '\*')
}

Re: ExtractFolder - Move contents of a folder out

Posted: 05 Sep 2024, 13:41
by leo007
Greetings @byzod, Thanks for sharing such a handy script.
Could you please share how to adjust the script so that "ExtractFolder" will be triggered by a hotkey without a context menu?

Many thanks in advance