Saving textfiles in a other folder
Show older comments
Hello there,
I try to open a text file in a other folder, replace "," with "." and to close and save.
It works, but the new text is saved in the folder of my matlabscript. But I want, that it saved there, where it tooks the textfile to manipulate it, just overwrite the old one.
Maybe someone can help me. Thanks!
addpath('E:\Data\Test\X')
testfiledir = 'E:\Data\Test\X';
matfiles = dir(fullfile(testfiledir, '*.txt'));
% A=dir ('*.txt')
B=matfiles(1).name;
FileName=B;
Data = fileread(FileName);
Data = strrep(Data, ',', '.');
FID = fopen(FileName, 'w');
fwrite(FID, Data, 'char');
fclose(FID);
% type FileName; hier nicht benötigt
M= readmatrix(FileName);
Accepted Answer
More Answers (0)
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!