Jump to content

Downloads folder macro?


Recommended Posts

How can you get the downloads folder in AutoIT?

As far as i know there isn't a macro for it right? like @Downloads or something?

The ugly solution would be typing in the whole path but what if the user has chosen another location?

Need to clear that folder regularly on my work and on different accounts..

regards, TheAutomator

Link to comment
Share on other sites

  • Moderators

Like so:

ShellExecute(@UserProfileDir & "\Downloads")

edit, I missed your "User has chosen another location". Typically I would say look at EnvGet, but don't think the Downloads folder is set as a typical environment variable. There is DEFAULT_DOWNLOADS, but that is for the default profile.

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

I know that if you change the path (and only if you change the path) it will show up in HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders, but it shows up as a GUID, like so:

Downloads.PNG

You could search for that, but would have to either load the user's registry hive or run it as them (startup script). And I believe several other folders, when changed, produce a similarly encoded name, so not sure how you would distinguish that {374DE290-...} is the new target for the Downloads folder and not something else. If the user goes so far as to redirect one folder, they may do so for others.

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

Yes, it could be ugly either way. You could do a fileExists, but unfortunately it won't tell you where the folder has been redirected. You would have to do something like this (pseudo):

If Not (FileExists(@UserProfileDir & "\Downloads")) Then
    For $a = 1 To 100
        $sVal = RegEnumVal("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", $a)
        If @error Then
            ExitLoop
        Else
            If StringInStr($sVal, "{374DE290-") Then
                ;further processing
            EndIf
        EndIf
    Next
EndIf

Even if you stick with the "ugly" C:\Users\TheAutomator\Downloads, if the user has moved the target you're sunk. Good luck with your project.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

This link has a lot of information about special folders, their GUIDs and default locations etc.

https://msdn.microsoft.com/en-us/library/windows/desktop/dd378457(v=vs.85).aspx

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

  • Moderators

So according to that page the GUID is static, after all. That should make things slightly easier for you, should you go that route, @TheAutomator

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...