Change file from equipment to .txt files

4 visualizzazioni (ultimi 30 giorni)
Tyler Lawson
Tyler Lawson il 4 Ott 2022
Risposto: Karim il 4 Ott 2022
I use equipment that when it saves files it saves them using date codes. For example, .924 or .929 for September 24th and 29th respectively. All they are are txt files and I can make MatLab change them to .txt files but only if I specify that I want a .929 file to change to .txt. How would I code it so that it takes all files and turns them to .txt so that when I have files from a whole week of equipment usage, I can just select a folder and not have to manually change the code for each date?
%Enter the directory to search
directory = uigetdir();
%List all .929 files
fileList = dir([directory, '\*.929');
%Loop through each 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']));
end

Risposta accettata

Karim
Karim il 4 Ott 2022
This would do the trick, see below for some comments.
% Enter the directory to search
directory = uigetdir();
% List all items in the folder
fileList = dir(directory);
% Delete the subfolders from the list (i.e. only keep files)
fileList(vertcat(fileList.isdir)) = [];
% Loop through each 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']));
end

Più risposte (0)

Categorie

Scopri di più su Variables in Help Center e File Exchange

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by