File Exchange

image thumbnail

GenerateDOSfilename

version 1.2.0.0 (1.38 KB) by Andreas Sprenger
Generates a unique string with 8 characters

0 Downloads

Updated 31 Mar 2014

View License

Sometimes it is neccessary to use a 8.3 filename on remote DOS systems (e.g. EyeLink eyetracking system). GenerateDOSfilename creates an unique string using date and time.

Comments and Ratings (2)

David

It's a great idea, but there's a typo. The minutes "Mn" obviously goes up to 59, which will give an error when trying to index the length-36 array. Replacing the last line with:

varargout = {[abc([Y-2000, M, D, H]) [num2str(Mn) num2str(round(S))]]};

should work better.

I'd also doubt that DOS will be gone by 2036, if it has hung on this long. There are 36^8 = 2.82e12 possible 8-character filenames, which should be enough for over 89000 years at a rate of one per second. We could use the date number function, and convert the result to base 36, to achieve this. You could try something like:

% Not rigorously tested!
abc = '0123456789abcdefghijklmnopqrstuvwxyz';
dnum = round(now*24*60*60); % Serial date number, with seconds as the whole number.
% now = datenum(now)
%
varargout = {abc(base36(dnum))};
%
function out = base36(in)
out = zeros(1,8);
for itO = 8:-1:1
out(itO) = mod(in, 36)+1;
in = floor(in/36);
end
end
%
end

which is admittedly a lot less elegant than yours, but will avoid that dreaded Y2036 bug!

Jos (10584)

Nice idea, although I will stick with my own version

filename = [datestr(now,'ddHHmmss') '.ext']

And shall we make a bet that DOS still is used in 2034?

Updates

1.2.0.0

Current version enables reconversion of generated string in date and time.

1.1.0.0

Bug removed (thanks to David)

MATLAB Release Compatibility
Created with R2013b
Compatible with any release
Platform Compatibility
Windows macOS Linux