MATLAB Answers

How to change file extension to '.xlsx' BUT keep original files?

18 views (last 30 days)
NH
NH on 22 Mar 2013
Hello,
I am trying to change files with extension '.stp' to '.xlsx' while also keeping the original '.stp' files. I have code that replaces the '.stp' files with '.xlsx', but it does not keep the originals:
files=dir('*.stp')
for i=1:length(files)
filename=files(i).name;
[pathstr, name, ext] = fileparts(filename);
movefile(filename, fullfile(pathstr, [name '.xlsx']))
end
Also, for some reason I am unable to open the resulting '.xlsx' files. However, when I write them to '.xls' they open with no problems. This is a problem because I need the files '.xlsx' format. If anyone knows how to solve this problem as well, it would be greatly appreciated.
I am running Matlab 2013a on a Mac.

  0 Comments

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 22 Mar 2013
Use copyfile() instead of movefile().

  3 Comments

NH
NH on 22 Mar 2013
Ah, Thank you!
I am still getting an error when trying to open the '.xlsx' files in excel. The error reads:
"The file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file."
Does anyone know how to fix this? If I don't get answer within a few days, I'll repost it to its own thread.
Thanks!
Kelly Kearney
Kelly Kearney on 22 Mar 2013
Changing the extension of a file doesn't change its format, only its name.
Image Analyst
Image Analyst on 22 Mar 2013
You'd need to read the data in with some kind of .stp file reader, into variables in MATLAB. Then write out those variables with xlswrite().

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by