Reputation: 33
I know that to create a new folder is mkdir
. But I was wondering if there was a way that I could setup a GUI so that it would create a new folder with the name of the subject by having a window within the GUI where someone can name type in the subject name then create a folder by a push button. Still new to creating GUIs. I suppose it would take some combination of Edit Text and a Push Button. Any help would be greatly appreciated.
Upvotes: 1
Views: 2318
Reputation: 9696
An alternative would be set the pushbutton-callback so something along this, similar to a "save as..." button in other applications:
function pushbutton_callback(hObject, evt, handles)
directory = uigetdir(pwd, 'Select Directory');
if ischar(directory)
set(handles.textfield, 'String', directory);
end
This way the user is prompted by a proper windows dialog to select a folder. This dialog also enables the user the create a new folder that is then inserted into your textfield. This is kind of the other way round then the original approach, but is the more common way for use-cases such as "select the directory where to save xxx".
Upvotes: 2
Reputation: 544
Assuming you have a Text Edit Box named 'TargetDirName_et', and a Push Button named 'CreateDir_pb' try the following:
In your code for the 'CreateDir_pb' push button callback:
function CreateDir_pb_Callback(hObject, eventdata, handles)
% hObject handle to CreateDir_pb (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
dirString= get(handles.TargetDirName_et,'String');
mkdir(dirString);
Upvotes: 1