matlab GUI 实现文件夹选择

matlab实现多个文件夹选择
function [pathname] = uigetdir2(start_path, dialog_title)
% Pick multiple directories and/or files

import javax.swing.JFileChooser;

if nargin == 0 || start_path == '' || start_path == 0 % Allow a null argument.
    start_path = pwd;
end

jchooser = javaObjectEDT('javax.swing.JFileChooser', start_path);

jchooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
if nargin > 1
    jchooser.setDialogTitle(dialog_title);
end

jchooser.setMultiSelectionEnabled(true);

status = jchooser.showOpenDialog([]);

if status == JFileChooser.APPROVE_OPTION
    jFile = jchooser.getSelectedFiles();
	pathname{size(jFile, 1)}=[];
    for i=1:size(jFile, 1)
		pathname{i} = char(jFile(i).getAbsolutePath);
	end
	
elseif status == JFileChooser.CANCEL_OPTION
    pathname = [];
else
    error('Error occured while picking file.');
end


单个文件夹选择
Open folder selection dialog box
使用

uigetdir

folder_name = uigetdir
folder_name = uigetdir(start_path)
folder_name = uigetdir(start_path,dialog_title)


Description

folder_name = uigetdir displaysa modal dialog box showing the folders that are inside the currentworking directory. This dialog allows you to navigate to a folderand select it (or type the name of a folder). If the folder you specifyexists, uigetdir returns the selected path whenyou click OK. If you click Cancel (orthe window's close box), uigetdir returns 0.

folder_name = uigetdir(start_path) showsthe folders that are inside the folder, start_path.If start_path is an empty string ('')or is not a valid path, the dialog box opens in the current workingdirectory.

folder_name = uigetdir(start_path,dialog_title) opensa dialog box with the title, dialog_title. Thedefault dialog_title is Select Directoryto Open.

Note:  The visual characteristics of the dialog box depend on the operatingsystem that runs your code. For instance, some operating systems donot show title bars on dialog boxes. If you pass a dialog box titleto the uigetdir function, those operating systems will not displaythe title.


 
 


获取文件

uigetfile

保存文件

uiputfile

保存变量到文件

uisave

Open dialog box for saving variables to MAT-file



猜你喜欢

转载自blog.csdn.net/ls1300005/article/details/51093285