Code covered by the BSD License  

Highlights from
CO2gui - lab control and automation

CO2gui - lab control and automation



06 Jan 2010 (Updated )

Software used for controlling and data logging lab equipment.

function lowerext(folderName)
% LOWEREXT changes all the extensions of the files in a folder to lower
% case (not recursive).  If no folder name is specified, then brings up a
% dialog asking for it.

% checks the folder was supplied
if ~nargin
    % gets the filename
    folderName = uigetdir;
    % if nothing was supplied, error
    if isequal(folderName, 0)
       % error
       error('Must select a folder.')
elseif nargin ~= 1
    % error
    error(nargchk(0, 1, nargin))
elseif exist(folderName, 'file') ~= 7
    % errors
    error('Not a valid folder to use.')

% gets the list of files in the folder
allFiles = dir(folderName);

% for each file...
for m = 1:numel(allFiles)
    % checks its not a directory first
    if ~allFiles(m).isdir
        % gets the extension (ignores the filepath since there is nothing
        % there anyway)
        [filePath, fileName, ext] = fileparts(allFiles(m).name);

        % if its not lower case, change it (ignores the '.')
        if any(isstrprop(ext(2:end), 'upper'))
            % defines the filenames
            source = [folderName, filesep, allFiles(m).name];
            destination = [folderName, filesep, fileName, lower(ext)];
            tempName = [folderName, filesep, 'temp.dat'];
            % rename the file - need to do it in two parts ffs
                % renames it to a temporary filename
                movefile(source, tempName)
                % renames it to the filename
                movefile(tempName, destination)
                % displays a warning
                warning('lowerExt:failedRename', 'Could not rename file')

Contact us