필터 지우기
필터 지우기

create a .txt file in a specific folder

조회 수: 20 (최근 30일)
Ahmed BOULMANE
Ahmed BOULMANE 2015년 7월 16일
편집: Stephen23 2015년 7월 17일
normally i use this:
mkdir('xxxx')
filename = ['xxxx\',FileName,'.txt'];"
to build the file name
and now the xxxx is variable so i can't do this 'xxxx\' any more, so how can i resolve this problem ? thank YOU!

답변 (1개)

Stephen23
Stephen23 2015년 7월 16일
편집: Stephen23 2015년 7월 17일
Rather than concatenating strings it is much more reliable to use fullfile to create filepaths:
dir_path = 'my_project_directory';
file_name = 'test1.txt';
mkdir(dir_path);
out = fullfile(dir_path,file_name)
Note that you do not need to specify any path separator characters as these are inserted by fullfile automatically (and of the correct type to match your OS).
Similarly it is also more reliable to build a filename using sprintf rather than string concatenation, e.g. to generate the above filename:
file_name = sprintf('test%d.txt',1);
  댓글 수: 2
Ahmed BOULMANE
Ahmed BOULMANE 2015년 7월 17일
I created the file 'filename.txt', and I created the folder 'dir_path', but, when I made fullfile (dir_path, filename), the file 'filename.txt' stay always outside of the folder 'dir_path', and what I want to do is to create the file 'filename' inside of the folder
Guillaume
Guillaume 2015년 7월 17일
You will have to show us the exact code you use to create the text file.

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

카테고리

Help CenterFile Exchange에서 Standard File Formats에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by