- List all files in a given directory with the extension .out
- Copy the file and rename the extention .txt
- Delete the .out file (commented out)
How to change file extension via matlab?
165 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ivan Mich
el 2 de Abr. de 2020
Comentada: Emmagnio Desir
el 1 de Abr. de 2023
Hello,
I have a question. I would like to change the extension of several files. I mean that in one directory a I have many files in type file1.out., file2.out ,..., file600.out.
I would like to rename these files to *.txt (I mean file1.txt, file2.txt,...., file600.txt) in this directory with one command via matlab?
Could anyone help me?
0 comentarios
Respuesta aceptada
Adam Danz
el 2 de Abr. de 2020
Editada: Adam Danz
el 27 de En. de 2021
This shows how to
% Enter the directory to search
directory = 'C:\Users\name\Documents\MATLAB';
% List all .out files
fileList = dir([directory, '\*.out']);
% Loop through each .out file, copy it and give new extension: .txt
for i = 1:numel(fileList)
file = fullfile(directory, fileList(i).name);
[tempDir, tempFile] = fileparts(file);
status = copyfile(file, fullfile(tempDir, [tempFile, '.txt']))
% Delete the .out file; but don't do this until you've backed up your data!!
% delete(file)
end
*Not tested
5 comentarios
Más respuestas (2)
Femke Cappon
el 27 de En. de 2021
Thank you, I have used to code to rewrite LabVIEW .lvm files to .txt
0 comentarios
Musaddiq Al Ali
el 6 de Dic. de 2020
Editada: Musaddiq Al Ali
el 6 de Dic. de 2020
Mr. Adam Danz's code is vey nice and neat. I like it. I would like to suggest, to add '\' to the secound lines of the code:-
fileList = dir([directory,'\','*.out']);
2 comentarios
Stephen23
el 6 de Dic. de 2020
Even better would be to use the correct function for the job:
fileList = dir(fullfile(directory,'*.out'));
Ver también
Categorías
Más información sobre Get Started with MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!