MATLAB Answers

Change file name to something else?

2 views (last 30 days)
Sameer Dave
Sameer Dave on 13 Nov 2019
Commented: Walter Roberson on 13 Nov 2019
I have several files in a folder that can be openend using notepad++ which has a number/characters in it. I would like to know if there is a way to look for those numbers/characters and add them to the name of the file.
e.g. File name: AB_123_CD_4567 ------> change this name to "AB_123_CD_4567_AB123" where AB123 was found within the file "AB_123_CD_4567".

  3 Comments

Rik
Rik on 13 Nov 2019
This is a three step process. Which of these steps do you have issues with?
  1. read the file
  2. find the text to add to the file name (if any)
  3. rename the file
Sameer Dave
Sameer Dave on 13 Nov 2019
I was more looking forward to the basic codes that would be used to carry all the steps out.
Walter Roberson
Walter Roberson on 13 Nov 2019
Reading the file: it is common that for cases like these, fileread() can be used. After that, regexp() is often useful for pulling out the part of the file you need. Then compute the new file name, and movefile()

Sign in to comment.

Answers (0)

Sign in to answer this question.