long paths: get paths from clipboard

Get help with using AutoHotkey and its commands and hotkeys
User avatar
jeeswg
Posts: 5555
Joined: 19 Dec 2016, 01:58
Location: UK

long paths: get paths from clipboard

08 May 2018, 10:00

- If you do Ctrl+C to copy a file with a long path to the clipboard (260+ characters), is it possible to retrieve that path programmatically?
- I used NirSoft InsideClipboard to investigate the clipboard after doing Ctrl+C, and it showed a Shell IDList Array clipboard format. When I tried to get the text of long paths, it only got some of the path.
- Any other ideas to get long paths from the clipboard would be welcome.

Code: Select all

;note: run the script after sending Ctrl+C to an Explorer window
q:: ;failed attempt to get 260+ char paths from the clipboard (it does get 259- char paths)
vList := JEE_ClipboardGetPathsAlt(vSep:="`r`n")
MsgBox, % StrLen(vList) "`r`n" vList
return

;==================================================

JEE_ClipboardGetPathsAlt(vSep:="`n")
{
	vFormat := DllCall("user32\RegisterClipboardFormat", Str,"Shell IDList Array", UInt)
	if !DllCall("user32\IsClipboardFormatAvailable", UInt,vFormat)
	|| !DllCall("user32\OpenClipboard", Ptr,0)
		return
	if !hData := DllCall("user32\GetClipboardData", UInt,vFormat, Ptr)
	{
		DllCall("user32\CloseClipboard")
		return
	}

	vSize := DllCall("kernel32\GlobalSize", Ptr,hData, UPtr)
	pData := DllCall("kernel32\GlobalLock", Ptr,hData, Ptr)
	VarSetCapacity(vData, vSize, 0)
	DllCall("kernel32\RtlMoveMemory", Ptr,&vData, Ptr,pData, UPtr,vSize)
	DllCall("kernel32\GlobalUnlock", Ptr,hData)

	;CIDA structure (Windows)
	;https://msdn.microsoft.com/en-us/library/bb773212.aspx

	vCount := 1+NumGet(&vData, 0, "UInt")
	VarSetCapacity(vOutput, vCount*260 << !!A_IsUnicode)
	Loop, % vCount
	{
		if (A_Index = 1)
			continue
		vOffset := NumGet(&vData, A_Index*4, "UInt")
		pITEMIDLIST := &vData+vOffset
		VarSetCapacity(vPath, 260*(A_IsUnicode?2:1), 0)
		DllCall("shell32\SHGetPathFromIDListW", Ptr,pITEMIDLIST, WStr,vPath)
		vOutput .= vPath vSep
	}

	DllCall("user32\CloseClipboard")
	return SubStr(vOutput, 1, -StrLen(vSep))
}
- My best workaround so far for listing the selected files in a folder (including long paths) is here:
259-char path limit workarounds - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 02#p217002

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, Gangass, Haasjes, nisha, steffn54 and 46 guests