Clear Filters
Clear Filters

Renaming Files

2 views (last 30 days)
Danielle Leblanc
Danielle Leblanc on 6 Aug 2011
I used 7 zip to split large excel files. It gave them to me in the following format: naic1.xlsx.001,...naic1.xlsx.029 for file 1 naic2.xlsx.001,...naic2.xlsx.030 for file 2 etc... naic29.xlsx.001,...naic2.xlsx.006 for file 29
I tried all the renaming functions in file exchange without any luck. I want to rename them as naic1.xlsx .....naic(a consecutive number I think it will be 833).xlsx Any help with that is greatly appreciated

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 6 Aug 2011
Something alone the line as below. Proceed with caution.
count=1;
for k=1:29
Files=dir(['naic',num2str(k),'.xlsx.*']);
for j=1:length(Files)
movefile(Files(j).name,['naic',num2str(count),'.xlsx']);
count=count+1;
end
end
  3 Comments
Fangjun Jiang
Fangjun Jiang on 6 Aug 2011
I think I might know the problem. Copy all your files to a temporal folder and run the code again. This time it uses movefile() and it also limit the files returned by dir(). You should also not to expect the code will work without any modification. I don't have the exact folder/files as you have. You should understand the code, do a little debugging and make it work.
Fangjun Jiang
Fangjun Jiang on 6 Aug 2011
Please note I've modified the code.

Sign in to comment.

More Answers (0)

Categories

Find more on File Operations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!