Hello
I have an old code using uigetfolder but when I run it I have error message: The function UIGETFOLDER only works on a MS-Windows PC. I wonder if I can use uigetdir to fix it or maybe there is beter way?
function folder = uigetfolder(title, initial_path)
%UIGETFOLDER Standard Windows browse for folder dialog box.
%
% folder = uigetfolder(title, initial_path)
%
% Output: folder = selected folder (empty string if dialog cancelled)
% Inputs: title = title string (OPTIONAL)
% initial_path = initial path (OPTIONAL, defaults to PWD)
%
% Examples: folder = uigetfolder - default title and initial path
% folder = uigetfolder('Select results folder') - default initial path
% folder = uigetfolder([], 'C:\Program Files') - default title
%
% See also UIGETFILE, UIPUTFILE
%-----------------------------------------------------------------------------------------------
if ~strcmp(computer, 'PCWIN')
error_dialog_handle = errordlg(['The function ', upper(mfilename), ' only works on a MS-Windows PC'], ...
mfilename, ...
'modal');
folder = '';
else
if nargin < 2
initial_path = pwd;
end
if nargin < 1 | isempty(title)
title = 'Select a folder';
end
% Error checking
if ~ischar(title)
error('The title must be a string')
end
if ~ischar(initial_path)
error('The initial path must be a string')
end
if ~exist(initial_path, 'dir')
error(['The initial path: ', initial_path, ' does not exist!'])
end
folder = uigetfolder_win32(title, initial_path);
end
%-----------------------------------------------------------------------------------------------

 Akzeptierte Antwort

YT
YT am 6 Feb. 2019
Bearbeitet: YT am 6 Feb. 2019

0 Stimmen

Wow I looked up this function on FEX and its last update was in the year 2000 (so its pretty much ancient). Like you said yourself, uigetdir(path, title) will work just fine (which was introduced in R2006a). Just remove the error_dialogue part en change uigetfolder_win32 to uigetdir.
function folder = uigetfolder(initial_path, title)
%UIGETFOLDER ^please note that I changed the position of initial_path and title; makes more sense
if nargin < 2
initial_path = pwd;
end
if nargin < 1 | isempty(title)
title = 'Select a folder';
end
% Error checking
if ~ischar(title)
error('The title must be a string')
end
if ~ischar(initial_path)
error('The initial path must be a string')
end
if ~exist(initial_path, 'dir')
error(['The initial path: ', initial_path, ' does not exist!'])
end
folder = uigetdir(initial_path, title);
end

4 Kommentare

Piotr Matysiak
Piotr Matysiak am 7 Feb. 2019
thanks now it works when i run it but i want to use it for saving many files and when i want to change folder i got message:
Not enough input arguments.
Error in uigetfolder (line 7)
if nargin < 1 | isempty(title)
Error while evaluating UIControl Callback.
Ah I see, change
isempty(title)
by
exist('title','var') == 0
and it should be fine
Piotr Matysiak
Piotr Matysiak am 7 Feb. 2019
Thank You for your quick answer! Everything is working fine ;)
YT
YT am 8 Feb. 2019
No problem. Please dont forget to click on the 'accept answer' button to close this question.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu App Building finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 6 Feb. 2019

Kommentiert:

YT
am 8 Feb. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by