From: Peter Smith on
Hi all,
I have about 80,000 files. I want to extract the beginning of the file name and get a vector of names. Examples of the files are as follows;

abc_129576.csv
shfs_1937t555.csv
kjsdg_297354.csv

as the file names range between two and four characters i am unsure how to extract the file name only.

Can anyone offer any solutions.

Many thanks
From: us on
On Jul 26, 6:50 pm, "Peter Smith" <fe0...(a)mail.wbs.ac.uk> wrote:
> Hi all,
> I have about 80,000 files. I want to extract the beginning of the file name and get a vector of names. Examples of the files are as follows;
>
> abc_129576.csv
> shfs_1937t555.csv
> kjsdg_297354.csv
>
> as the file names range between two and four characters i am unsure how to extract the file name only.
>
> Can anyone offer any solutions.
>
> Many thanks

one of the many solutions

flst={
'abc_129576.csv'
'de_12xyz.csv'
'fgh_ijk'
};
r=regexp(flst,'\w+(?=_)','match');
r=[r{:}]
% r = 'abc' 'de' 'fgh'

us
From: Peter Smith on
us <us(a)neurol.unizh.ch> wrote in message <969b6f48-15ef-4036-900f-df82529ed7a3(a)l14g2000yql.googlegroups.com>...
> On Jul 26, 6:50 pm, "Peter Smith" <fe0...(a)mail.wbs.ac.uk> wrote:
> > Hi all,
> > I have about 80,000 files. I want to extract the beginning of the file name and get a vector of names. Examples of the files are as follows;
> >
> > abc_129576.csv
> > shfs_1937t555.csv
> > kjsdg_297354.csv
> >
> > as the file names range between two and four characters i am unsure how to extract the file name only.
> >
> > Can anyone offer any solutions.
> >
> > Many thanks
> Thanks for your quick and precise answer

> one of the many solutions
>
> flst={
> 'abc_129576.csv'
> 'de_12xyz.csv'
> 'fgh_ijk'
> };
> r=regexp(flst,'\w+(?=_)','match');
> r=[r{:}]
> % r = 'abc' 'de' 'fgh'
>
> us
From: us on
"Peter Smith" <fe09ae(a)mail.wbs.ac.uk> wrote in message <i2khqh$8hm$1(a)fred.mathworks.com>...
> us <us(a)neurol.unizh.ch> wrote in message <969b6f48-15ef-4036-900f-df82529ed7a3(a)l14g2000yql.googlegroups.com>...
> > On Jul 26, 6:50 pm, "Peter Smith" <fe0...(a)mail.wbs.ac.uk> wrote:
> > > Hi all,
> > > I have about 80,000 files. I want to extract the beginning of the file name and get a vector of names. Examples of the files are as follows;
> > >
> > > abc_129576.csv
> > > shfs_1937t555.csv
> > > kjsdg_297354.csv
> > >
> > > as the file names range between two and four characters i am unsure how to extract the file name only.
> > >
> > > Can anyone offer any solutions.
> > >
> > > Many thanks
> > Thanks for your quick and precise answer

ok...
there was no need, by the way, to change your name
from
alex eptas
to
peter smith

us
From: dpb on
Peter Smith wrote:
> Hi all, I have about 80,000 files. I want to extract the beginning of
> the file name and get a vector of names. Examples of the files are as
> follows;
>
> abc_129576.csv
> shfs_1937t555.csv
> kjsdg_297354.csv
>
> as the file names range between two and four characters i am unsure how
> to extract the file name only.
>
> Can anyone offer any solutions.

Alternatively, potentially useful depending on the application...

>> dir *.dat

A.Dat C.Dat FMT.DAT MON.DAT TEST1.DAT WORK.DAT
B.DAT DATE.DAT JUNK.DAT TEST.DAT TEXT.DAT save.dat

>> d=dir('*.dat');
>> for idx=1:length(d), [p,n,e]=fileparts(d(idx).name);disp(n),end
A
B
C
DATE
FMT
JUNK
MON
save
TEST
TEST1
TEXT
WORK
>>

--
 | 
Pages: 1
Prev: Matlab's Inverse
Next: 3D-FDTD