Code covered by the BSD License  

Highlights from
browseforfolder

image thumbnail
from browseforfolder by Ohad Gal
Enhanced dialog box for folder browsing.

uibrowseforfolder( title_str, initial_path )
function folder = uibrowseforfolder( title_str, initial_path )
%UIBROWSEFORFOLDER    Standard Windows browse for folder dialog box.
%
%   folder = uibrowseforfolder( title_str, initial_path )
%
%   Output: folder       = selected folder (empty string if dialog cancelled)
%   Inputs: title_str    = title string (OPTIONAL)
%           initial_path = initial path (OPTIONAL, defaults to PWD)
%
%   Examples:   folder = uibrowseforfolder                          - default title and initial path
%               folder = uibrowseforfolder('Select results folder') - default initial path
%               folder = uibrowseforfolder([], 'C:\Program Files')  - with no title
%

%
%   1. using mex function browseforfolder.dll
%   2. credit for "C++" code goes to Armen Hakobyan
%      code taken from "The Code Project"
%      at: http://www.codeproject.com/dialog/cfolderdialog.asp
%   3. coverted to matlab mex file by Ohad Gal.
%   4. some operating systems need two additional DLLs in this zip:
%      msvcrtd.dll and MFC42D.DLL
%

% check input parameters
switch (1)
    case (nargin==0),
        title_str       = 'Please select a folder';
        initial_path    = pwd;
    case (nargin==1),
        initial_path    = pwd;
end

% check for valid input
if isempty(initial_path)
    initial_path = pwd;
end
if isempty(title_str) & (nargin>0)
    title_str = ' ';    % we can't send an empty string, send "space" instead
end

% more valid checks
if size(initial_path,1)>size(initial_path,2)
    initial_path = initial_path';
end
if size(title_str,1)>size(title_str,2)
    title_str = title_str';
end

% call the function
folder = browseforfolder( title_str, initial_path );
if isnumeric(folder)
    folder = '';
end

Contact us at files@mathworks.com