How to Get the Downloads Folder Path C11

Hi All,

Does anybody knows how to Get the Downloads Folder Path in c11 and windows 11 64 bit

This may work
Command Prompt

echo %USERPROFILE%\Downloads

Powershell

(Get-ItemProperty “HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders”).‘{374DE290-123F-4565-9164-39C4925E467B}’

if you know the user profile

C:\Users\username\Downloads

Cheers

Thx ! I will give it a try

I got the environement variable C:\Users\username so it works now.

I tried SHGetKnownFolderPath

MODULE(‘shell32.dll’)
SHGetKnownFolderPath(*LPCGUID rfid, ULONG dwFlags, ULONG hToken, *ULONG ppszPath), LONG, PASCAL, RAW, NAME(‘SHGetKnownFolderPath’)
END
but couldn’t get it working

I guess this is a yes, but did you add the Download folder to the environment path?

If you got the environment variable, it should work, unless the program is not running under the user and lack the permissions to write to that folder.

Yes it is working. Thx

C:\Users\username\downloads

Hi Drik,

I had Claude create a class to do this (So no RUN etc. required).

Repo is here: msarson/GetKnownFolderPathClass: Clarion class wrapping the Windows SHGetKnownFolderPath API (ANSI, 32-bit, runtime-loaded)

It dynamically loads SHGetKnownFolderPath at runtime so there is no lib required either.

I hope this help you, and anyone else needing something for this.

Usage

  INCLUDE('KnownFolderPath.inc'),ONCE

FolderPath CSTRING(32767)
Folders    KnownFolderPath

  CODE
  IF Folders.GetFolder(KnownFolderNo:Downloads, FolderPath) = KnownFolder:Success
    MESSAGE(FolderPath)
  ELSE
    MESSAGE(Folders.LastError())
  END

UPDATED FOR CLARION 12 UNICODE BETA

  INCLUDE('KnownFolderPathW.inc'),ONCE

FolderPath USTRING(32767)
Folders    KnownFolderPathW

  CODE
  IF Folders.GetFolderW(KnownFolderNo:Downloads, FolderPath) = KnownFolder:Success
    MESSAGE(FolderPath)
  ELSE
    MESSAGE(Folders.LastError())
  END

Mark

Getting the info out of the registry seems a little heavy-handed to me. Three are some files in the libsrc directory called CSIDL… which deal with special folders

something like downloadspath = svSpecialFolder.getdir(sv:csidl_personal)
then strip off "Documents " from the end and add “Downloads”

CSIDL is soooooo 2007 :wink:

Ah well, just when you find that Clarion actually provides you with a way to deal with something rather than roll your own, you find out the thing is deprecated anyway.

Thx all and specially Mark,

All solutions work. What is the most best/robust one?

FWIW, the latest version of our ProPath templates use Known Folders (they used to use CSIDL - you are SO right Jane :slight_smile: ). Not only the Downloads folder, but all others.

ProPath makes it trivial to put your data files, INI files, etc anywhere you need them to be.

This includes data files in a shared location and local per-user files on the user’s own machine or putting some files in one location and other files in different locations.

It also supports multiple data sets with the ability to change them at startup and at runtime.

You can also open Windows Explorer directly to any folder (including the Known Folder list) to give your users easy access.

Plus you can package and deploy files to your users for startup or demo data and have them automatically put where they need to be on demand or in a “First Run” scenario.

Docs here:

More info here:
https://clarionproseries.com/html/propath.html

Charles

Hi Mark Sarson,

I am using your solution. Thx. I was wondering if it also can work with the
Universal Naming Convention (UNC)?

I have a simple function to change a path to UNC

Hi Dirk,

Glad it’s useful. Yes, it works with UNC paths. The class returns whatever location Windows has for the folder and doesn’t change it:

  • Folder redirected to a network share (e.g. by Group Policy): Windows already returns the UNC path, such as \server\users$\dirk\Documents, and you get that as is.
  • Folder redirected to a mapped drive (e.g. H:\Documents): you get the drive-letter path. Pass it through your UNC function:
UncPath = YourToUNC(Folders.GetPath(KnownFolderNo:Documents))
  • Local folder (C:\Users...): there’s no UNC form to convert to, apart from admin shares like \PC\C$.

GetPath(..., TRUE) works fine with UNC paths and doesn’t add a second backslash. The only exception is KnownFolderFlag:DefaultPath, which ignores redirection and always returns the default local location.

:+1:Great, thanks again