Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
list box removing path

Subject: list box removing path

From: Alex

Date: 2 Feb, 2013 23:49:08

Message: 1 of 2

I have a gui with 2 listboxes that contain the same files, one with pathname + filename, the other with just the filenames. I have the listbox populated with filenames shown, while the listbox containg the paths hidden under an axes (so that I only have to look at the filenames, and not their path too).
The problem I'm having is that if I add files from more than one path, only the paths of the most recently files added are kept, and the paths of the other files are removed leaving only the the filename. I dont know why this is happening, and thanks on advance for any help!

for the code below:
inputFiles_listbox holds only the filenames
namefile_listbox holds the pathname+filename

% --- Executes on button press in add_file.
function add_file_Callback(hObject, eventdata, handles)

global input_file
global newNames

% gets input file(s) from user
[input_file,pathname] = uigetfile( ...
    {'*.asc', 'ASCII (*.asc)'; ...
    '*.*', 'All Files (*.*)'}, ...
    'Select files', ...
    'MultiSelect', 'on',...

% if file selection is cancelled, pathname should be zero and nothing should happen
if pathname == 0

% assignin('base','pathname',pathname)
% handles.pathname = pathname; % Holds pathname in handles structure to be passed to output files.

% gets the current data file names inside the listbox
newFileNames = get(handles.inputFiles_listbox,'String');
inputFileNames = get(handles.inputFiles_listbox,'String');

% if only one file is selected, then the data will not be a cell
% if more than one file selected at once, then the data will be stored inside a cell
if iscell(input_file) == 0
    %add the most recent data file selected to the cell containing all the data file names
    newFileNames{end+1} = fullfile(pathname,input_file);
    inputFileNames{end+1} = fullfile(input_file);
else % data will be in cell format
    for n = 1:length(input_file)
        % braces, {}, are used because cells are being used.
        newFileNames{end+1} = fullfile(pathname,input_file{n})
        inputFileNames{end+1} = fullfile(input_file{n})

% updating the gui to display all filenames in the listbox

% make sure first file is always selected so it doesn't go out of range
% the GUI will break if this value is out of range

% Update handles structure
guidata(hObject, handles);

Subject: list box removing path

From: Alex

Date: 2 Feb, 2013 23:57:08

Message: 2 of 2

a few things to note,
1. the code pasted above if for a pushbutton that is used to add the files.

2. the last line of code in this part:

% gets input file(s) from user
[input_file,pathname] = uigetfile( ...
    {'*.asc', 'ASCII (*.asc)'; ...
    '*.*', 'All Files (*.*)'}, ...
    'Select files', ...
    'MultiSelect', 'on',...

should be changed to something else if you are going to run this code.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us