text file to be in the folder

조회 수: 1 (최근 30일)
PA
PA 2022년 7월 14일
답변: Karim 2022년 7월 14일
if i run the code i create the folder and the text file is created in it but text are not displayed in the text file. i tried with pwd also but it didnot work
  댓글 수: 1
PA
PA 2022년 7월 14일
the code is here
label_1 = '# Screw';
fid = fopen ('screw size.txt','wt');
fprintf (fid,'%s\n', Label_1 );
t = now;
folder1 = ['SCREW' nameProject, datestr(t, 'yyyymmdd')];
if (isfolder(folder1))
delete([folder1, '\*'])
else
mkdir(folder1)
end
save(fullfile(folder1, 'screw size.txt'), 'fid') ;
fclose (fid);

댓글을 달려면 로그인하십시오.

답변 (1개)

Karim
Karim 2022년 7월 14일
No need for the save command, first create the folder (or check that it exists) and then you can write the file directly into the folder. See below for the steps
% first create folder
t = now;
folder1 = ['SCREW' datestr(t, 'yyyymmdd')];
if isfolder(folder1)
delete([folder1, '\*'])
else
mkdir(folder1)
end
% now create the file and its contents
label_1 = '# Screw';
fid = fopen(fullfile(folder1, 'screw size.txt'),'wt');
fprintf(fid,'%s\n', label_1);
fclose(fid);

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by