Change file from equipment to .txt files

1 view (last 30 days)
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

Accepted Answer

Karim
Karim on 4 Oct 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

More Answers (0)

Categories

Find more on Variables in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!