allDate = datetime(zeros(1,length(Filename)));
will only work if length(Filename) is 3 or 6. Otherwise you'll get an error. Even if you don't get an error, your array is initialised with just one datetime: 30 Nov 1 00:00:00
The simplest way to initialise it would be:
allDate = NaT(size(Filename));
which will create a datetime array full of Not A Time.
The code doesn't fail, but my allDate output looks like this
I would expect that if k is 6 and never goes through 1 to 5. allDate consists of that initial datetime(0, 0, 0) you put in there at index 1, NaT (not a time) for flling the indices between 1 and 6, and the value you put in at index 6.