TheAutomator

Downloads folder macro?

9 posts in this topic

#1 ·  Posted

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi JLogan3o13

Thanks for the quick reply.
I'm just thinking out loud here:

Imagine: the user has set the downloads folder path on the desktop or something?

[EDIT]

Oh i see, hmm.. small but tricky problem huh :)

Edited by TheAutomator

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#6 ·  Posted

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.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#7 ·  Posted

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

Share this post


Link to post
Share on other sites

#8 ·  Posted

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


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
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

  • Similar Content

    • 9252Survive
      By 9252Survive
      Hi All, 
       
      I am fairly new to AutoIT and I am still trying to learn, I have been using _FileListToArray to list all the files with a particular extension in an array and then loop through it for operation  (   For $i = 1 To UBound($FileArray) - 1).
      So far this has been working fine. But I am not able to figure out a problem that I have; what if I have 50 files but I only want to loop through first 10 files and then next ten and so on?  Or rather I should say, how I can I only feed max 10 files to the array at a time when I do _FileListToArray regardless of the total number of files in the folder?
      Any insight/help will be much appreciated 
    • Mag91
      By Mag91
      Hey Everybody,
      as you know im on a very low autoit-level.
      My question is: How can i read all PDFs from a Folder wich is open and copy them to a Folder on a Desktop.
       
      The Folder wich contains the PDFs is variable Z:\Projektls\"*"*"*EVERYTIME ANOTHER ENDING"*"*"*"*"
      There can be 1 PDF or even 15 PDFs.
      i tried it with _FileListToArray and _FileCopy but i Need some help to understand this language
       
      THANKS!
       
    • TheSaint
      By TheSaint
      Some of you might find this little program I whipped up yesterday, to be useful. I had a need and it was filled.
      It is pretty basic and I admit was pretty much slapped together speedily and then fine tuned some time later, and could certainly do with more improving, if you care to do so.
      Thanks to Jefrey for his 'parse.au3' for the PHP elements. Source found here. I also used my Dropbox code, found here.

      Gutenberg Project page I used for the screenshot - http://www.gutenberg.org/ebooks/1965
      One of their links looks like - http://www.gutenberg.org/ebooks/1965.epub.images?session_id=5932cd1d25afee6150a958323abd8a32d68249a7
      V1.3
      Basically, the Download Dropbox program aims to simplify and speed up downloading of files, with Batch and easy sub-folder creation.
      Everything in the program is done by either Drag & Drop or clicking a button. Window floats on top of others, naturally.
      1. Drag a folder to the Destination input field to set the destination path.
      2. Highlight some text, then drag that text to the drop zone (top edit field), to create the first sub-folder (if you want one). Click the SUB FOLDER button to assign it.
      3. Do the same for the next sub-folder (if you want one or instead of the other sub folder). Click the TITLE button to assign it.
      4. Select and drag a link (URL) to the drop zone. Click the ADD button to have it added to the Download list (last field).
      5. Repeat for more files, that you wish to send to the same destination.
      6. Click the DOWNLOAD button to have them start downloading.
      If size of each download can be determined, you will see the Progress bar working.
      All the buttons & List have a CTRL key feature, some also have a SHIFT key one. See the Program Information dialog for details.
      Drop zone and other inputs, can also be typed or pasted into.
      Some settings are saved to INI file and recalled on subsequent executions or the click of a button with CTRL held down.
      NOTE - I particularly like the Text Drag ability, as that simplifies things when doing lots of sub-folders. No browsing required.
      ADVICE - Clicking an entry in the list field, will momentarily display its full link text in the drop zone. Entries on the List are not sorted, so they appear in the order added. Obviously I wanted the program to take up as least desktop space as feasible, so that means truncated list entries etc.
      WARNING - Before doing a bunch of links from a site, where the links are not straight forward, do a test run of one. Especially as there is currently no STOP button.
      Downloads Dropbox v1.2.zip  (includes au3 & exe) See above for required 'parse.au3' file.
      Downloads Dropbox v1.3.zip
      IMPROVEMENTS & LIMITATIONS
      I have tailored certain elements for Gutenberg Project downloads and another site or two, so things will not work out-of-the-box for all possible download sites. That means you will have to tweak the code for some sites. Straight forward download links (no tricky php) seem to work fine. In particular, while what you might want to get downloads fine, it may be missing the file extension and not have the desired name.
      Sometimes, if you drag & drop an image onto the drop zone, the image will display there, and you cannot grab its URL. In those cases, I just right click the original image, grab its URL and paste that into the drop zone. You can clear the displayed image (and any other entry in the drop zone) by holding down CTRL while clicking the DOWNLOAD button.
      At this stage, you can only batch download files that you want, to the same destination. I am considering adding a multiple destination ability.
      Need to add a STOP button.
      P.S. This is my first second full program with the latest AutoIt.
    • SkysLastChance
      By SkysLastChance
      I have a Razer Blackwidow Ultimate keyboard that has 5 extra keys marked M1 - M5. I was wondering if I would be able to setup Macros in AutoIt using these.
      I saw that Fn key is not possible. 
      I am also aware that the M1 keys work with razor snyapse. However, I am at work and can't download that program.
      If someone could let me know and point me in the right direction if it is possible I would be grateful.
    • ur
      By ur
      We can get a list of file using the below code.
      Local $aFileList = _FileListToArray(@DesktopDir, "*") Is there any option to use the above one recursively to get sub folders and their contents also.??
      And also, is there any way to serialize the above array locally to some file and load it later when we want in another program on another machine so that we can compare its contents with a folder in different machine, which is not network connected also.?