필터 지우기
필터 지우기

Change file from equipment to .txt files

조회 수: 2 (최근 30일)
Tyler Lawson
Tyler Lawson 2022년 10월 4일
답변: Karim 2022년 10월 4일
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

채택된 답변

Karim
Karim 2022년 10월 4일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Variables에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by