function [f] = setBackslash(theDir,varargin)
% setBackslash  takes care fo the last character in a directory name
%
%syntax:
%   [f] = setBackslash(theDir,action)
%
%   varargin
%            'set'   : the last character will be a \ (default)
%            'remove': a possible backslash is removed
%
%   f      = the corrected directory


if nargin == 1
    action = 'set';
else
    action = varargin{1};
end

if iscell(theDir)
    f=theDir{1,:};
else
    f=theDir;
end

if strcmpi(action,'set')
    if ~strcmpi(f(length(f)),'\')
        f=[f '\'];
    end
else strcmpi(action,'remove')
    if strcmpi(f(length(f)),'\')
        f=f(1:length(f)-1);
    end
end

end