MATLAB Answers


Rename file with date

Asked by joo tan on 12 Jul 2012
Dear all..
i have many file with name by modified julian date..i have used matlab progrrming JD2CAL (Converts Julian date to calendar date using algorithm).. It is succesfull but the problem is when day in January , November and December..For example 1112007.txt represent for 11/1/2007 but problem for file date 1/11/2007 also will rename the file with 1112007.txt..So, the data for this two date will mix i can solve it?

  1 Comment

on 12 Jul 2012
What if use notation like DS_MM_YYYR.txt (for eg. 01_11_2007.txt) ...?

Sign in to comment.

2 Answers

Answer by Jan
on 12 Jul 2012
Edited by Jan
on 12 Jul 2012

Either use 2 digits for the day and the month, or add a separator.
sprintf('%.2d%.2d%.4d', 1, 1, 2007)
sprintf('%d_%d_%d', 1, 1, 2007)
I'd prefer this, because the alphabetical order equals the temporal order:
sprintf('%.4d%.2d%.2d', year, month, day)


Sign in to comment.

Azzi Abdelmalek
Answer by Azzi Abdelmalek
on 16 Jul 2012
Edited by Azzi Abdelmalek
on 8 Aug 2012

file=[file '.txt']


joo tan on 8 Aug 2012
Dear Azzi
my file is not name like 11/1/2012..original file is julian date. after i convert to calendar date, it will clash between file for date 1 november and 11 jan because this file will have name 111 at i need to modified to make different name 0111 for 1 Nov and 1101 for 11 jan
Image Analyst
on 8 Aug 2012
joo tan, you'll note that you did not give any examples of your initial, original filenames/strings, or the desired, ending filenames. You just gave one filename so it's not clear what you are starting with. We don't know if you have actual filenames that you need to convert, or some strings that you want to build up with the current date that you will then use to create the file, or something else. If you clarified your situation, you'd eliminate all the confusion and guessing that you're causing.
Star Strider
on 9 Aug 2012
The jd2cal function returns [yr,mn,dy]. It is not the source of the ambiguity.

Sign in to comment.