필터 지우기
필터 지우기

files managing (copy, move and write)

조회 수: 3 (최근 30일)
kimy
kimy 2021년 8월 4일
편집: kimy 2021년 8월 6일
Hi,
Now I have a series of files but I don't know how to achieve my goal using Matlab since I am a definitely beginer. I have a folder called surface in which many folders are included, named by a time step (0.1, 0.2 ,0.3 .....). Of course, under each time step folder the data file (e.g. "0.1->patch_ground->scalarfiled->p") that I need is there, as you can recognise in the attchment, which is original data files that I output from an OPENFOAM code I have to write al data included in the file "p" to another file "p" with header under the folder of each timestep ("0.1->p"). By the same procedure, apply for each time step folder with a loop I think. I hope anybody can give me some tips, thanks a lot.

채택된 답변

Simon Chan
Simon Chan 2021년 8월 4일
In your attached file, there is already a file 'p' inside folder '0.1' and I need to remove this file before running the following code. Otherwise, error would occur because copy or move a file onto itself is not allowed.
So please be aware to make sure all file with name 'p' only stored in the subdirectory 'C:\...\patch_ground\scalarField'.
listfolder = dir('**/p');
initial = {listfolder.folder};
destination = cellfun(@(x) strrep(x,'patch_ground\scalarField',''),initial,'UniformOutput',false);
cellfun(@(x,y) copyfile(fullfile(x,'p'),fullfile(y,'p')),initial,destination)
  댓글 수: 13
kimy
kimy 2021년 8월 5일
Thanks, it works well. I am thinking that it is better to process the data file before combining header file. But I faild to modify it. I simply tried e.g. "newdata=data-1000".
kimy
kimy 2021년 8월 6일
편집: kimy 2021년 8월 6일
I tried many times and I faild to arange the data inside "p" file. Could you give me some tips? Thanks.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by