Change file from equipment to .txt files
1 回表示 (過去 30 日間)
古いコメントを表示
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
0 件のコメント
採用された回答
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Environment and Settings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!