Find Downloads folder from MATLAB

Is there a way to programmatically find the Downloads folder path on a Windows system (from within MATLAB)?

 採用された回答

Cam Salzberger
Cam Salzberger 2018 年 4 月 11 日

2 投票

Hello Matt,
Probably the easiest way would be to use environment variables to get close to the location. The USERPROFILE variable will normally get you C:\Users\username, so you could simply do:
dlDir = fullfile(getenv('USERPROFILE'), 'Downloads');
Alternatively, you could build the file path using just the USERNAME variable:
dlDir = fullfile('C:\Users', getenv('USERNAME'), 'Downloads');
Or you could try a non-environment-variable method, using the userpath. By default, userpath on Windows is usually C:\Users\username\Documents\MATLAB, so you could parse out the first part of that using fileparts or strsplit. Then add 'Downloads' with fullfile.
However, all of these depend on one or more of these directories being in the standard location for Windows. Before using the directory, it is probably a good idea to check that it exists first. Otherwise you may error, or create it, depending on how you use it.
-Cam

3 件のコメント

Matt J
Matt J 2018 年 4 月 11 日
Thanks, Cam. That works great.
Walter Roberson
Walter Roberson 2018 年 4 月 11 日
The active Downloads folder can depend what the user configured in their browser, which is not something that would be stored in the registry.
Matt J
Matt J 2018 年 4 月 11 日
That's okay for my purposes. I'm interested in the conventional Downloads folder location.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeDownloads についてさらに検索

質問済み:

2018 年 4 月 11 日

コメント済み:

2018 年 4 月 11 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by