1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- function [dataFilename dataFolder] = getFile(filterSpec, title)
- % getFile
- %
- % Similar to uigetfile, it opens a dialogue to get a file, but it also
- % remembers the last folder location, so the user will not need to navigate
- % to the same folder multiple times.
- %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % Use [dataFilename dataFolder] = getFile(filterSpec)
- %
- % filterSpec: The type of file to show. For example, if set to '*.txt'
- % (OPTIONAL) only text files will be visible for choosing.
- % DEFAULT: *.*, so all files are shown.
- %
- % title: This parameter will be the title of the dialogue box.
- % (OPTIONAL) DEFAULT: No title will be shown.
- %
- % dataFilename: The name of the chosen file.
- %
- % dataFolder: The path of the chosen file.
- %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % USAGE EXAMPLE:
- %
- % [fileName pathName] = getFile('*.jpg');
- %
- % In this example a dialogue will open and only show all jpg files. The
- % name of the chosen file and the path to it are stores in fileName and
- % pathName respectively.
- %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % Kian Torab
- % ktorab@blackrockmicro.com
- % Blackrock Microsystems
- % Salt Lake City, UT
- % Contributors:
- %
- % Version 1.0.0.0 - October 29, 2010
- % Last edit by: Kian Torab
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- if ~exist('filterSpec', 'var')
- filterSpec = '*.*';
- end
- if ~exist('title', 'var')
- title = '';
- end
- settingFileFullPath = getSettingFileFullPath('getFile');
- %% Opens the getFolder.ini file to see what the last accessed folder was
- if exist(settingFileFullPath, 'file') == 2
- settingsFID = fopen(settingFileFullPath, 'r');
- defaultOpenLocation = fscanf(settingsFID, '%200c');
- fclose(settingsFID);
- [dataFilename dataFolder] = uigetfile([defaultOpenLocation filterSpec], title);
- else
- [dataFilename dataFolder] = uigetfile(filterSpec, title);
- end
- %% Saves the last opened folder in the getFolder.ini file for later use
- if ischar(dataFolder)
- settingsFID = fopen(settingFileFullPath, 'w');
- fprintf(settingsFID, '%s', dataFolder);
- fclose(settingsFID);
- end
|