Copy the files with the same names from many folders into new one folder

Dear all, could anyone help with this issue? We want to copy files with same names from many folders into new one folder. Example: 001/aaa.tiff, 002/aaa.tiff, ..., 555/aaa.tiff. - result new/001.tiff,002.tiff,003.tiff
If I do the dir of the folder there appears this list of folders: ., .., 001, 002, and so on. It is a structure array and I am not familiar with that.
Thanks for any advice, Ludek

回答 (3 件)

Ludek
Ludek 2012 年 1 月 13 日

0 投票

Thank you Chandra for help, it works.
One more question to make it more elegant. We have a hundreds of folders each with one image. How to make to read all the folders (the names of all begins 000) automatically in the variable "sourcefolders"?
Thank you, Ludek

1 件のコメント

Chandra Kurniawan
Chandra Kurniawan 2012 年 1 月 13 日
for x = 1: 555
sourcefolders{x} = num2str(x,'%03i');
end

サインインしてコメントする。

Ludek
Ludek 2012 年 1 月 13 日

0 投票

There is one problem
Warning: Unexpected results may occur with signed pixel data. In imwrite at 443 In New at 9
The Img as a Matlab variable is correct, but the imwrite command doesn't work. We get files in new folder but it these images are empty just only zero values.
Thanks for any advice, Ludek

1 件のコメント

Chandra Kurniawan
Chandra Kurniawan 2012 年 1 月 13 日
The use copyfile instead
for num = 1 : length(sourcefolders)
file = dir(fullfile(sourcefolders{num},filename));
newname = strcat(num2str(num,'%03i'),'.tif');
copyfile(fullfile(sourcefolders{num},file.name),fullfile(destinationfolder,newname));
end

サインインしてコメントする。

Ludek
Ludek 2012 年 1 月 13 日

0 投票

Thank you! You help us a lot. Ludek

カテゴリ

ヘルプ センター および File ExchangeFile Operations についてさらに検索

質問済み:

2012 年 1 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by