ExtractFolder - Move contents of a folder out

Post your working scripts, libraries and tools.
byzod
Posts: 89
Joined: 21 Jun 2021, 06:46

ExtractFolder - Move contents of a folder out

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

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

Return to “Scripts and Functions (v2)”

Who is online

Users browsing this forum: Marium0505, songdg and 21 guests