files managing (copy, move and write)

3 次查看(过去 30 天)
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".

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by