Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Concatenate many binary files in one

Subject: Concatenate many binary files in one

From: Camille Couzi

Date: 2 Sep, 2011 07:30:27

Message: 1 of 6

Hi matlab friends!
I have thousands of little binary files (.000 extension, RDI adcp files that can be open with WinADCP software) that i would like to concatenate in only one. The problem is that I have no idea of how these files are structured, and I would like to keep this same (unknown) structure for the total end file.

For the moment, I have wrote:

%%%------------------BEGINNING OF CODE

folder='C:\Matlab\Work';
list_files = dir(fullfile(folder,'*.000'));

num_files=length(list_files); %number of files in the folder
data=cell(num_files,1);

for f=1:length(list_files)
   
    filename=list_files(f).name; %complete filename
    path_file=fullfile(folder,filename);
    
    fid=fopen(path_file,'r');
    data(f,1)={fread(fid,'ubit64')};
    fclose(fid);
    
end

data_tot = cat(1,data{:}) ;

fid2=fopen(fullfile(folder,'Zero_total.000'),'w');
fprintf(fid2,'%s\t',char(data_tot));
fclose(fid2);

%%%------------------END OF CODE

It produces my Zero_total.000 file, which is not empty, but of course when i try to open it in WinADCP software, as I have (apparently) modificated the structure of the binary file, it doens't want to open it...

Anybody has an idea?

Thanks in advance for your help!!!

Subject: Concatenate many binary files in one

From: Luis FIlipe Ferreira Marques Santos

Date: 2 Sep, 2011 10:56:26

Message: 2 of 6

"Camille Couzi" <camillecouzi@yahoo.fr> wrote in message <j3q0mj$p23$1@newscl01ah.mathworks.com>...
> Hi matlab friends!
> I have thousands of little binary files (.000 extension, RDI adcp files that can be open with WinADCP software) that i would like to concatenate in only one. The problem is that I have no idea of how these files are structured, and I would like to keep this same (unknown) structure for the total end file.
>
> For the moment, I have wrote:
>
> %%%------------------BEGINNING OF CODE
>
> folder='C:\Matlab\Work';
> list_files = dir(fullfile(folder,'*.000'));
>
> num_files=length(list_files); %number of files in the folder
> data=cell(num_files,1);
>
> for f=1:length(list_files)
>
> filename=list_files(f).name; %complete filename
> path_file=fullfile(folder,filename);
>
> fid=fopen(path_file,'r');
> data(f,1)={fread(fid,'ubit64')};
> fclose(fid);
>
> end
>
> data_tot = cat(1,data{:}) ;
>
> fid2=fopen(fullfile(folder,'Zero_total.000'),'w');
> fprintf(fid2,'%s\t',char(data_tot));
> fclose(fid2);
>
> %%%------------------END OF CODE
>
> It produces my Zero_total.000 file, which is not empty, but of course when i try to open it in WinADCP software, as I have (apparently) modificated the structure of the binary file, it doens't want to open it...
>
> Anybody has an idea?
>
> Thanks in advance for your help!!!

Hi Camille.

I had a similar problem, I run a C++ software that generated me near a hundred TXT files with data.

I've used the command line from windows to concatenate all the files.

The only requests are:

- They need to have a similar name. Example:
abc1.txt
abc2.txt
abc3.txt
.
.
.
and so...
- And they all need to be in the same folder.

And the command line (DOS) for the above example is:
type abc*.txt > allabc.txt

were the file allabc will be the concatenated file containing all the other files.

I hope I've been a good help. :)

Regards

Subject: Concatenate many binary files in one

From: Camille Couzi

Date: 5 Sep, 2011 01:31:11

Message: 3 of 6

Hola luis, como va?!

Thanks for your message.
I have made a trial: I put my files in the folder C:\Temp, I named them file1.dat file2.dat file3.dat... ( changed the extension to .dat).

And then in the cmd I go to this folder:
cd C:\Temp
and I write what you told me:
type file*.dat > allfiles.dat

And I get this error message:
file*.dat is not recognized as and internal or external command, operable command or batch file.

What's the problem? when I go to C:\Temp I can see that a file allfiles.dat has been created but is (of course) empty.

Gracias por la ayuda, saludos de singapur!


"Luis FIlipe Ferreira Marques Santos" wrote in message <j3qcoq$sop$1@newscl01ah.mathworks.com>...
> "Camille Couzi" <camillecouzi@yahoo.fr> wrote in message <j3q0mj$p23$1@newscl01ah.mathworks.com>...
> > Hi matlab friends!
> > I have thousands of little binary files (.000 extension, RDI adcp files that can be open with WinADCP software) that i would like to concatenate in only one. The problem is that I have no idea of how these files are structured, and I would like to keep this same (unknown) structure for the total end file.
> >
> > For the moment, I have wrote:
> >
> > %%%------------------BEGINNING OF CODE
> >
> > folder='C:\Matlab\Work';
> > list_files = dir(fullfile(folder,'*.000'));
> >
> > num_files=length(list_files); %number of files in the folder
> > data=cell(num_files,1);
> >
> > for f=1:length(list_files)
> >
> > filename=list_files(f).name; %complete filename
> > path_file=fullfile(folder,filename);
> >
> > fid=fopen(path_file,'r');
> > data(f,1)={fread(fid,'ubit64')};
> > fclose(fid);
> >
> > end
> >
> > data_tot = cat(1,data{:}) ;
> >
> > fid2=fopen(fullfile(folder,'Zero_total.000'),'w');
> > fprintf(fid2,'%s\t',char(data_tot));
> > fclose(fid2);
> >
> > %%%------------------END OF CODE
> >
> > It produces my Zero_total.000 file, which is not empty, but of course when i try to open it in WinADCP software, as I have (apparently) modificated the structure of the binary file, it doens't want to open it...
> >
> > Anybody has an idea?
> >
> > Thanks in advance for your help!!!
>
> Hi Camille.
>
> I had a similar problem, I run a C++ software that generated me near a hundred TXT files with data.
>
> I've used the command line from windows to concatenate all the files.
>
> The only requests are:
>
> - They need to have a similar name. Example:
> abc1.txt
> abc2.txt
> abc3.txt
> .
> .
> .
> and so...
> - And they all need to be in the same folder.
>
> And the command line (DOS) for the above example is:
> type abc*.txt > allabc.txt
>
> were the file allabc will be the concatenated file containing all the other files.
>
> I hope I've been a good help. :)
>
> Regards

Subject: Concatenate many binary files in one

From: Camille Couzi

Date: 5 Sep, 2011 02:06:10

Message: 4 of 6

Hi again :-)
problem solved, and I got exactly what I wanted so thanks a lot!!!

Subject: Concatenate many binary files in one

From: TideMan

Date: 5 Sep, 2011 04:46:16

Message: 5 of 6

On Sep 5, 2:06 pm, "Camille Couzi" <c...@dhi.com.sg> wrote:
> Hi again :-)
> problem solved, and I got exactly what I wanted so thanks a lot!!!

But Camille..............
Luis was concatenating ASCII files, whereas you have binary files.
I think you need to run BBConv from RDITools on each .000 file first
and convert to ASCII files, then concatenate those.
But perhaps I'm wrong .................

Subject: Concatenate many binary files in one

From: Camille Couzi

Date: 5 Sep, 2011 06:28:07

Message: 6 of 6

Ey tideman.
I heard about BBconv before, but in fact when doing what Luis told me, it works properly... :-)

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us