Rename file with date

4 次查看(过去 30 天)
joo tan
joo tan 2012-7-12
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 ..it also will rename the file with 1112007.txt..So, the data for this two date will mix together..how i can solve it?
  1 个评论
TAB
TAB 2012-7-12
What if use notation like DS_MM_YYYR.txt (for eg. 01_11_2007.txt) ...?

请先登录,再进行评论。

回答(2 个)

Jan
Jan 2012-7-12
编辑:Jan 2012-7-12
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)

Azzi Abdelmalek
Azzi Abdelmalek 2012-7-16
编辑:Azzi Abdelmalek 2012-8-8
file=datestr(datenum(date),'dd/mm/yyyy')
file([3,6])=[]
file=[file '.txt']
  3 个评论
Image Analyst
Image Analyst 2012-8-8
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
Star Strider 2012-8-9
The jd2cal function returns [yr,mn,dy]. It is not the source of the ambiguity.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Calendar 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by