I think we have a nice set of built-in variables that are flexible enough to do a lot of interesting things, but I keep thinking we are missing the A_Downloads variable that would point to the default location the downloads folder at in a similar fashion to A_MyDocuments!
Unless there is a technical reason preventing this, it sounds a bit better than EnvGet('SystemDrive') '\Users\' A_UserName '\Downloads'
A_Downloads might be a nice thing to have at some point.
Re: A_Downloads might be a nice thing to have at some point.
Code: Select all
; V1
RegRead, A_Downloads, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders, {374DE290-123F-4565-9164-39C4925E467B}
; V2
A_Downloads := RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", "{374DE290-123F-4565-9164-39C4925E467B}")
Re: A_Downloads might be a nice thing to have at some point.
or
Code: Select all
A_Downloads := ComObject('Shell.Application').NameSpace('Shell:Downloads').Self.Path
Re: A_Downloads might be a nice thing to have at some point.
yeah! those are great! i have used the one @autoexec posted before...
but hear me out: how about just A_Downloads??
That way you don't have to find those in the forums every time you need it? just type A_Downloads and you are good to go. xD
but hear me out: how about just A_Downloads??
That way you don't have to find those in the forums every time you need it? just type A_Downloads and you are good to go. xD
Projects:
AHK-ToolKit
AHK-ToolKit
- Animan8000
- Posts: 58
- Joined: 11 May 2022, 05:00
- Contact:
Re: A_Downloads might be a nice thing to have at some point.
A little unrelated, but I generally don't recommend using "A_UserName" for trying to find subfolders (downloads, pictures, etc.) of a user folder. Because A_UserName contains only the username, and not necessarily the user folder name. Depending on how Windows is installed, the script can break, if the user folder is for example shortened by Windows automatically. For example fully reinstalling Windows locally without an external drive (USB for example) did typically shorten the user folder name to only 5 characters, effectively making A_UserName pointless in this situation, and I used A_AppData instead, and went to the folder above, to avoid that inconsistencyRaptorX wrote: ↑19 Apr 2024, 17:08I think we have a nice set of built-in variables that are flexible enough to do a lot of interesting things, but I keep thinking we are missing the A_Downloads variable that would point to the default location the downloads folder at in a similar fashion to A_MyDocuments!
Unless there is a technical reason preventing this, it sounds a bit better than EnvGet('SystemDrive') '\Users\' A_UserName '\Downloads'
Re: A_Downloads might be a nice thing to have at some point.
Totally correct, I usually use the above code only on my machine for quick scripts but I totally forgot that installing the "offline" version of windows messes with the User folder for whatever reason.Animan8000 wrote: ↑24 Apr 2024, 07:22A little unrelated, but I generally don't recommend using "A_UserName" for trying to find subfolders (downloads, pictures, etc.) of a user folder. Because A_UserName contains only the username, and not necessarily the user folder name. Depending on how Windows is installed, the script can break, if the user folder is for example shortened by Windows automatically. For example fully reinstalling Windows locally without an external drive (USB for example) did typically shorten the user folder name to only 5 characters, effectively making A_UserName pointless in this situation, and I used A_AppData instead, and went to the folder above, to avoid that inconsistencyRaptorX wrote: ↑19 Apr 2024, 17:08I think we have a nice set of built-in variables that are flexible enough to do a lot of interesting things, but I keep thinking we are missing the A_Downloads variable that would point to the default location the downloads folder at in a similar fashion to A_MyDocuments!
Unless there is a technical reason preventing this, it sounds a bit better than EnvGet('SystemDrive') '\Users\' A_UserName '\Downloads'
But basically that is part of my argument, instead of having to rely on workarounds to find that folder I think it would be a nice addition to have it behave as the builtin variables for "A_AppData" or "A_MyDocuments".
The reason why I think this might not get implemented is that people can change the location of the Downloads folder (which is something I do) by going to the preferences and setting the downloads location to a new place like this:
But I would say you can do the same with "My Documents" but I am not sure how "A_MyDocuments" react to that... does it point to the new location, if it does, then I would have the same expectation for the proposed "A_Downloads".
Projects:
AHK-ToolKit
AHK-ToolKit
Re: A_Downloads might be a nice thing to have at some point.
agree, wish other folders like A_picture A_video exited.
Re: A_Downloads might be a nice thing to have at some point.
Code: Select all
#Requires Autohotkey v2.0
; ----------------------------------------------------------------------------------------------------------------------
KF := GetKnownFoldersPaths()
; ----------------------------------------------------------------------------------------------------------------------
GetKnownFoldersPaths() {
Local KnownFolders := {}
; ===================================================================================================================
; IKnownFoldersManager interface
; https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-iknownfoldermanager
; CLSID_KnownFoldersManager = "{4DF0C730-DF9D-4AE3-9153-AA6B82E9795A}"
; IID_IKnownFoldersManager = "{8BE2D872-86AA-4d47-B776-32CCA40C7018}"
; ===================================================================================================================
Local IKFM := ComObject("{4DF0C730-DF9D-4AE3-9153-AA6B82E9795A}", "{8BE2D872-86AA-4d47-B776-32CCA40C7018}")
; Gets an array of all registered known folder IDs. This can be used in enumerating all known folders.
; https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-iknownfoldermanager-getfolderids
Local KFID := 0
Local CID := 0
ComCall(5, IKFM, "PtrP", &KFID, "IntP", &CID)
; Loop thru all returned folder IDs.
Local IKF := 0
Local StrPtr := 0
Local KFP := 0
Local Alias := ""
Local Path := ""
Local PKFID := KFID ; pointer to the current KNOWNFOLDERID
Loop CID {
; Gets an object that represents a known folder identified by its KNOWNFOLDERID.
; https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-iknownfoldermanager-getfolder
ComCall(6, IKFM, "Ptr", PKFID, "PtrP", &IKF)
; Retrieves a structure that contains the defining elements of a known folder,
; which includes the folder's category, name, path, description, tooltip, icon, and other properties.
; https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-iknownfolder-getfolderdefinition
Local KFD := Buffer(40 + (A_PtrSize * 9), 0)
ComCall(11, IKF, "Ptr", KFD.Ptr)
; Get the Name field of the structure
Alias := StrReplace(StrGet(NumGet(KFD, A_PtrSize, "UPtr")), " ")
; Free the strings pointed to by structure fields
FreeKnownFolderDefinitionFields(KFD)
; Retrieve the path of the known folder as a string.
; https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-iknownfolder-getpath
Path := ""
If !ComCall(6, IKF, "UInt", 0, "PtrP", &KFP, "UInt") {
Path := ExpandEnvironmentStrings(StrGet(KFP))
DllCall("Ole32.dll\CoTaskMemFree", "Ptr", KFP)
}
; Release the IKnownFolder interface
IKF := 0
; Add the name and path to the object, if a path was retrieved
If !(Path = "")
KnownFolders.%Alias% := Path
; Switch to the next KNOWNFOLDERID
PKFID += 16
}
; Free the KnownFolderID object
DllCall("Ole32.dll\CoTaskMemFree", "Ptr", KFID)
; Release the IKnownFolderManager interface
IKFM := 0
; Return the folder object
Return KnownFolders
; -------------------------------------------------------------------------------------------------------------------
FreeKnownFolderDefinitionFields(KFD) {
Static OffSets := [A_PtrSize, A_PtrSize, A_PtrSize + 16, A_PtrSize, A_PtrSize, A_PtrSize, A_PtrSize, A_PtrSize]
Local Offset := 0
For O In Offsets {
Offset += O
DllCall("Ole32.dll\CoTaskMemFree", "Ptr", NumGet(KFD.Ptr + OffSet, "UPtr"))
}
}
; -------------------------------------------------------------------------------------------------------------------
ExpandEnvironmentStrings(Str) {
Local Chars := 0
Local Expanded := ""
If (Chars := DllCall("ExpandEnvironmentStringsW", "Str", Str, "Ptr", 0, "UInt", 0, "Int")) {
VarSetStrCapacity(&Expanded, ++Chars)
DllCall("ExpandEnvironmentStringsW", "Str", Str, "Str", &Expanded, "UInt", Chars, "Int")
}
Return (Chars ? Expanded : Str)
}
}
; ======================================================================================================================
Main := Gui( , "KnownFolders")
Main.OnEvent("Close", (*) => ExitApp())
Main.SetFont("s10", "Lucida Console")
MainLV := Main.AddListView("w1200 r30 Grid", ["Index", "Alias", "Path"])
For K In KF.OwnProps()
MainLV.Add("", A_Index, K, KF.%K%)
Loop MainLV.GetCount("Column")
MainLV.ModifyCol(A_Index, "AutoHdr")
Main.Show()
Re: A_Downloads might be a nice thing to have at some point.
Surprised to see it hasn't been mentioned, as it's the strategy I use exclusively: A_Desktop "\..\Downloads"
Almost everything accepts these kinds of paths, and it's dead simple to write. Granted, it is less simple than having A_Downloads would be.
Almost everything accepts these kinds of paths, and it's dead simple to write. Granted, it is less simple than having A_Downloads would be.
Re: A_Downloads might be a nice thing to have at some point.
Also if you just need to open the Downloads folder, Run "shell:Downloads"
Re: A_Downloads might be a nice thing to have at some point.
Where can I get a list of other system folders that can be opened this way. I tried "shell:Pictures", "shell:Recycle Bin", "shell:Documents" as a test, but they didn't work. Maybe my syntax is wrong... I was guessing based on your example... lol.
I did get "shell:Desktop" to work.
Re: A_Downloads might be a nice thing to have at some point.
https://www.elevenforum.com/t/list-of-windows-11-shell-commands-for-shell-folder-shortcuts.1080/
If you need these to work on an older version of windows,
should work as well.
If you need these to work on an older version of windows,
Code: Select all
Run "shell:::{374DE290-123F-4565-9164-39C4925E467B}"
Re: A_Downloads might be a nice thing to have at some point.
Sometimes you can also do:
Someone needs to boot up an old version of Windows 7/10 to test which one is the best for compatibility
Code: Select all
Run "::{374DE290-123F-4565-9164-39C4925E467B}"
Re: A_Downloads might be a nice thing to have at some point.
Actually just use this code if you need the actual path: viewtopic.php?p=286094#p286094
Make sure to rewrite this into 4 lines max
Make sure to rewrite this into 4 lines max
Re: A_Downloads might be a nice thing to have at some point.
ste(phen|ve) kunkel
Who is online
Users browsing this forum: fertalizer, pedro45_vs and 20 guests