From: Alex Eptas on
Hi,
I have thousands of files containing various information about stocks. However, i want to make a list of dates but the file names vary in length as the stock ID's are between 2 and 4 characters long. For example,

TSCO_20081225
TT_20081224
VED_20081224

If all stocks were the same character length i could simply use;

dates = unique(cellstr(fnames(;5:12)));

However this will not work due to the differences in stock ID length. Furthermore it is not possible to rename all files manually as there are about 70,000 files.

What could you recommend to solve this problem?

Many thanks your help would be appreciated

Alex
From: Rune Allnor on
On 25 Jul, 17:55, "Alex Eptas" <fe0...(a)mail.wbs.ac.uk> wrote:
> Hi,
> I have thousands of files containing various information about stocks. However, i want to make a list of dates but the file names vary in length as the stock ID's are between 2 and 4 characters long. For example,
>
> TSCO_20081225
> TT_20081224
> VED_20081224
>
> If all stocks were the same character length i could simply use;
>
> dates = unique(cellstr(fnames(;5:12)));
>
> However this will not work due to the differences in stock ID length. Furthermore it is not possible to rename all files manually as there are about 70,000 files.
>
> What could you recommend to solve this problem?
>
> Many thanks your help would be appreciated
>
> Alex

The 'correct' solution is to use regular expressions.

However, if *all* the filenames look like the above, I would
search for the underscore:

uscorepos = find(fname == '_');
stockID = fname(1:uscorepos-1);

Rune
From: Alex Eptas on
Rune Allnor <allnor(a)tele.ntnu.no> wrote in message <7b215e75-c848-4b85-99be-a694d6728553(a)5g2000yqz.googlegroups.com>...
> On 25 Jul, 17:55, "Alex Eptas" <fe0...(a)mail.wbs.ac.uk> wrote:
> > Hi,
> > I have thousands of files containing various information about stocks. However, i want to make a list of dates but the file names vary in length as the stock ID's are between 2 and 4 characters long. For example,
> >
> > TSCO_20081225
> > TT_20081224
> > VED_20081224
> >
> > If all stocks were the same character length i could simply use;
> >
> > dates = unique(cellstr(fnames(;5:12)));
> >
> > However this will not work due to the differences in stock ID length. Furthermore it is not possible to rename all files manually as there are about 70,000 files.
> >
> > What could you recommend to solve this problem?
> >
> > Many thanks your help would be appreciated
> >
> > Alex
>
> The 'correct' solution is to use regular expressions.
>
> However, if *all* the filenames look like the above, I would
> search for the underscore:
>
> uscorepos = find(fname == '_');
> stockID = fname(1:uscorepos-1);
>
> Rune

Hi Rune
Thanks for your quick reply
Unfortunately when i tried that it did noit work.
Could you or anyone else recommend something else?
Many many thanks
Alex
From: Alex Eptas on
Rune Allnor <allnor(a)tele.ntnu.no> wrote in message <7b215e75-c848-4b85-99be-a694d6728553(a)5g2000yqz.googlegroups.com>...
> On 25 Jul, 17:55, "Alex Eptas" <fe0...(a)mail.wbs.ac.uk> wrote:
> > Hi,
> > I have thousands of files containing various information about stocks. However, i want to make a list of dates but the file names vary in length as the stock ID's are between 2 and 4 characters long. For example,
> >
> > TSCO_20081225
> > TT_20081224
> > VED_20081224
> >
> > If all stocks were the same character length i could simply use;
> >
> > dates = unique(cellstr(fnames(;5:12)));
> >
> > However this will not work due to the differences in stock ID length. Furthermore it is not possible to rename all files manually as there are about 70,000 files.
> >
> > What could you recommend to solve this problem?
> >
> > Many thanks your help would be appreciated
> >
> > Alex
>
> The 'correct' solution is to use regular expressions.
>
> However, if *all* the filenames look like the above, I would
> search for the underscore:
>
> uscorepos = find(fname == '_');
> stockID = fname(1:uscorepos-1);
>
> Rune

Hi Rune
Thanks for your quick reply
Unfortunately when i tried that it did noit work.
Could you or anyone else recommend something else?
Many many thanks
Alex
From: Rune Allnor on
On 25 Jul, 18:36, "Alex Eptas" <fe0...(a)mail.wbs.ac.uk> wrote:
> Rune Allnor <all...(a)tele.ntnu.no> wrote in message <7b215e75-c848-4b85-99be-a694d6728...(a)5g2000yqz.googlegroups.com>...
> > On 25 Jul, 17:55, "Alex Eptas" <fe0...(a)mail.wbs.ac.uk> wrote:
> > > Hi,
> > > I have thousands of files containing various information about stocks. However, i want to make a list of dates but the file names vary in length as the stock ID's are between 2 and 4 characters long. For example,
>
> > > TSCO_20081225
> > > TT_20081224
> > > VED_20081224
>
> > > If all stocks were the same character length i could simply use;
>
> > > dates = unique(cellstr(fnames(;5:12)));
>
> > > However this will not work due to the differences in stock ID length. Furthermore it is not possible to rename all files manually as there are about 70,000 files.
>
> > > What could you recommend to solve this problem?
>
> > > Many thanks your help would be appreciated
>
> > > Alex
>
> > The 'correct' solution is to use regular expressions.
>
> > However, if *all* the filenames look like the above, I would
> > search for the underscore:
>
> > uscorepos = find(fname == '_');
> > stockID = fname(1:uscorepos-1);
>
> > Rune
>
> Hi Rune
> Thanks for your quick reply
> Unfortunately when i tried that it did noit work.
> Could you or anyone else recommend something else?
> Many many thanks
> Alex

You have to *try* it before you start wining:

>> fname= 'ABC_1234567890';
>> uscorepos = find(fname == '_');
>> stockID = fname(1:uscorepos-1)


stockID =

ABC

Rune