Batch rename MODIS data?












1














I have MOD13Q1 NDVI images. Data are named in this format:



MOD13Q1.A2007049.h26v06.006.2015161224938_MODIS_Grid_16DAY_250m_500m_VI.tif  


(YYYYDDD) Here 2007 is a year and 049 is day in year.



I have to rename it in this format: (YYYY.MM.DD) 2007.02.18



I am renaming it manually for every single file. How to perform a batch process for renaming all the files?










share|improve this question





























    1














    I have MOD13Q1 NDVI images. Data are named in this format:



    MOD13Q1.A2007049.h26v06.006.2015161224938_MODIS_Grid_16DAY_250m_500m_VI.tif  


    (YYYYDDD) Here 2007 is a year and 049 is day in year.



    I have to rename it in this format: (YYYY.MM.DD) 2007.02.18



    I am renaming it manually for every single file. How to perform a batch process for renaming all the files?










    share|improve this question



























      1












      1








      1







      I have MOD13Q1 NDVI images. Data are named in this format:



      MOD13Q1.A2007049.h26v06.006.2015161224938_MODIS_Grid_16DAY_250m_500m_VI.tif  


      (YYYYDDD) Here 2007 is a year and 049 is day in year.



      I have to rename it in this format: (YYYY.MM.DD) 2007.02.18



      I am renaming it manually for every single file. How to perform a batch process for renaming all the files?










      share|improve this question















      I have MOD13Q1 NDVI images. Data are named in this format:



      MOD13Q1.A2007049.h26v06.006.2015161224938_MODIS_Grid_16DAY_250m_500m_VI.tif  


      (YYYYDDD) Here 2007 is a year and 049 is day in year.



      I have to rename it in this format: (YYYY.MM.DD) 2007.02.18



      I am renaming it manually for every single file. How to perform a batch process for renaming all the files?







      r modis batch date string






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 24 mins ago









      Andre Silva

      7,105113578




      7,105113578










      asked 5 hours ago









      Tilok Chetri

      145




      145






















          2 Answers
          2






          active

          oldest

          votes


















          1














          If you were to use R language (open source), this will work.



          setwd("C:/modis") #path of modis files
          li<-as.data.frame(list.files(pattern = ".tif|.TIF"))
          li$nn<-paste0(substr(li[,1],1,9),format(as.Date(substr(li[,1],10,16), "%Y%j"),"%Y.%m.%d"),substr(li[,1],17,75))
          for(i in 1:nrow(li)){
          file.rename(as.character(li[i,1]),li[i,2])
          }





          share|improve this answer





























            1














            Suppose the following files:



            MOD13Q1.A2007049.h26v06.006.2015161224938_MODIS_Grid_16DAY_250m_500m_VI.tif
            MOD13Q1.A2007051.h26v06.006.2015161224938_MODIS_Grid_16DAY_250m_500m_VI.tif


            and that they are stored in directory C:/modis_files



            Run:



            setwd('C:\modis_files') #path to folder where MODIS files are.

            file.rename(list.files(), paste(as.Date(substr(list.files(),10,16),"%Y%j"),".tif", sep=""))


            It will result in:



            2007-02-18.tif
            2007-02-20.tif




            If you want to keep the entire file name, while only replacing the [year + julian days], then Bharadwaj A K's answer is the one.






            share|improve this answer























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "79"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f307324%2fbatch-rename-modis-data%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              If you were to use R language (open source), this will work.



              setwd("C:/modis") #path of modis files
              li<-as.data.frame(list.files(pattern = ".tif|.TIF"))
              li$nn<-paste0(substr(li[,1],1,9),format(as.Date(substr(li[,1],10,16), "%Y%j"),"%Y.%m.%d"),substr(li[,1],17,75))
              for(i in 1:nrow(li)){
              file.rename(as.character(li[i,1]),li[i,2])
              }





              share|improve this answer


























                1














                If you were to use R language (open source), this will work.



                setwd("C:/modis") #path of modis files
                li<-as.data.frame(list.files(pattern = ".tif|.TIF"))
                li$nn<-paste0(substr(li[,1],1,9),format(as.Date(substr(li[,1],10,16), "%Y%j"),"%Y.%m.%d"),substr(li[,1],17,75))
                for(i in 1:nrow(li)){
                file.rename(as.character(li[i,1]),li[i,2])
                }





                share|improve this answer
























                  1












                  1








                  1






                  If you were to use R language (open source), this will work.



                  setwd("C:/modis") #path of modis files
                  li<-as.data.frame(list.files(pattern = ".tif|.TIF"))
                  li$nn<-paste0(substr(li[,1],1,9),format(as.Date(substr(li[,1],10,16), "%Y%j"),"%Y.%m.%d"),substr(li[,1],17,75))
                  for(i in 1:nrow(li)){
                  file.rename(as.character(li[i,1]),li[i,2])
                  }





                  share|improve this answer












                  If you were to use R language (open source), this will work.



                  setwd("C:/modis") #path of modis files
                  li<-as.data.frame(list.files(pattern = ".tif|.TIF"))
                  li$nn<-paste0(substr(li[,1],1,9),format(as.Date(substr(li[,1],10,16), "%Y%j"),"%Y.%m.%d"),substr(li[,1],17,75))
                  for(i in 1:nrow(li)){
                  file.rename(as.character(li[i,1]),li[i,2])
                  }






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 1 hour ago









                  Bharadwaj A K

                  373




                  373

























                      1














                      Suppose the following files:



                      MOD13Q1.A2007049.h26v06.006.2015161224938_MODIS_Grid_16DAY_250m_500m_VI.tif
                      MOD13Q1.A2007051.h26v06.006.2015161224938_MODIS_Grid_16DAY_250m_500m_VI.tif


                      and that they are stored in directory C:/modis_files



                      Run:



                      setwd('C:\modis_files') #path to folder where MODIS files are.

                      file.rename(list.files(), paste(as.Date(substr(list.files(),10,16),"%Y%j"),".tif", sep=""))


                      It will result in:



                      2007-02-18.tif
                      2007-02-20.tif




                      If you want to keep the entire file name, while only replacing the [year + julian days], then Bharadwaj A K's answer is the one.






                      share|improve this answer




























                        1














                        Suppose the following files:



                        MOD13Q1.A2007049.h26v06.006.2015161224938_MODIS_Grid_16DAY_250m_500m_VI.tif
                        MOD13Q1.A2007051.h26v06.006.2015161224938_MODIS_Grid_16DAY_250m_500m_VI.tif


                        and that they are stored in directory C:/modis_files



                        Run:



                        setwd('C:\modis_files') #path to folder where MODIS files are.

                        file.rename(list.files(), paste(as.Date(substr(list.files(),10,16),"%Y%j"),".tif", sep=""))


                        It will result in:



                        2007-02-18.tif
                        2007-02-20.tif




                        If you want to keep the entire file name, while only replacing the [year + julian days], then Bharadwaj A K's answer is the one.






                        share|improve this answer


























                          1












                          1








                          1






                          Suppose the following files:



                          MOD13Q1.A2007049.h26v06.006.2015161224938_MODIS_Grid_16DAY_250m_500m_VI.tif
                          MOD13Q1.A2007051.h26v06.006.2015161224938_MODIS_Grid_16DAY_250m_500m_VI.tif


                          and that they are stored in directory C:/modis_files



                          Run:



                          setwd('C:\modis_files') #path to folder where MODIS files are.

                          file.rename(list.files(), paste(as.Date(substr(list.files(),10,16),"%Y%j"),".tif", sep=""))


                          It will result in:



                          2007-02-18.tif
                          2007-02-20.tif




                          If you want to keep the entire file name, while only replacing the [year + julian days], then Bharadwaj A K's answer is the one.






                          share|improve this answer














                          Suppose the following files:



                          MOD13Q1.A2007049.h26v06.006.2015161224938_MODIS_Grid_16DAY_250m_500m_VI.tif
                          MOD13Q1.A2007051.h26v06.006.2015161224938_MODIS_Grid_16DAY_250m_500m_VI.tif


                          and that they are stored in directory C:/modis_files



                          Run:



                          setwd('C:\modis_files') #path to folder where MODIS files are.

                          file.rename(list.files(), paste(as.Date(substr(list.files(),10,16),"%Y%j"),".tif", sep=""))


                          It will result in:



                          2007-02-18.tif
                          2007-02-20.tif




                          If you want to keep the entire file name, while only replacing the [year + julian days], then Bharadwaj A K's answer is the one.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited 27 mins ago

























                          answered 42 mins ago









                          Andre Silva

                          7,105113578




                          7,105113578






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.





                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                              Please pay close attention to the following guidance:


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f307324%2fbatch-rename-modis-data%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Understanding the information contained in the Deep Space Network XML data?

                              Ross-on-Wye

                              Eastern Orthodox Church