How to delete a string in multiple files by using eraseBetween (R2019a)

1 vue (au cours des 30 derniers jours)
Blue
Blue le 22 Mai 2019
Hello,
I am trying without success to delete a specific string (everything between xmln= and the next space) in multiple text files (xml files) by using the function eraseBetween. The files would then be moved to a new folder. The code so far is below. Any help welcome.
modified_xml = fullfile(pwd, 'modified_xml')
if exist([pwd '\modified_xml'])~=7
mkdir(modified_xml);
end
InputOldFiles = dir(fullfile('*.xml'));
OldFilesNames = {InputOldFiles.name};
for k = 1 : length(InputOldFiles)
OldFiles = OldFilesNames{k};
FID = fopen(OldFiles, 'r');
if FID == -1, error('Cannot open file'), end
% Delete specific string (everything between xmlns= and the next empty space)
text = textscan(FID, '%s', 'delimiter', '\n', 'whitespace', '');
new_text = eraseBetween(text,"xmlns="," ");
NewFiles = fopen(OldFiles, 'w');
if NewFiles == -1, error('Cannot open file'), end
% Save the file
fprintf(NewFiles, '%s\n', new_text{:});
fclose(NewFiles);
% Copy the files
copyfile(OldFiles, NewFiles);
end

Réponses (0)

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Tags

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by