matlab 生成一个文件夹,matlab – 创建一个用户可以选择文件或文件夹的对话框

我们可以使用Java组件,特别是

JFileChooser,并确保我们为它提供了FILES_AND_DIRECTORIES选择标志.

%% Select entity:

jFC = javax.swing.JFileChooser(pwd);

jFC.setFileSelectionMode(jFC.FILES_AND_DIRECTORIES);

returnVal = jFC.showOpenDialog([]);

switch returnVal

case jFC.APPROVE_OPTION

fName = string(jFC.getSelectedFile());

case jFC.CANCEL_OPTION

% do something with cancel

case jFC.ERROR_OPTION

% do something with error

otherwise

throw(MException("fileFolderChooser:unsupportedResult", ...

"Unsupported result returned from JFileChooser: " + returnVal + ...

". Please consult the documentation of the current Java version (" + ...

string(java.lang.System.getProperty("java.version")) + ")."));

end

%% Process selection:

switch true % < this is just some trick to avoid if/elseif

case isfolder(fName)

% Do something with folder

case isfile(fName)

% Do something with file

otherwise

throw(MException('fileFolderChooser:invalidSelection',...

'Invalid selection, cannot proceed!'));

end

这产生了一个熟悉的对话框,如下所示,它完全按预期工作:

78593d65c08d23da81df86c7f5c8cc43.png

在R2018a上测试,使用Java 1.8.0_144(java.lang.System.getProperty(“java.version”)的输出).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值