Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Search a file on the basis of numeric fields part of filename

Reply
Thread Tools

Search a file on the basis of numeric fields part of filename

 
 
chiku
Guest
Posts: n/a
 
      06-26-2009
Hi,
I have collection of files having names like TripIdSegId.src, where
TripId and SegId are numeric fields which is part of filename string.
Now i want to search file with lowest TripId and SegId from the given
directory.

Could anyone help me how to achieve this in code?

Chiku
 
Reply With Quote
 
 
 
 
Ron
Guest
Posts: n/a
 
      06-26-2009
On Jun 26, 7:43*am, chiku <(E-Mail Removed)> wrote:
> Hi,
> I have collection of files having names like TripIdSegId.src, where
> TripId and SegId are numeric fields which is part of filename string.
> Now i want to search file with lowest TripId and SegId from the given
> directory.
>

C++ doesn't really give you any way to search directories. You'll
have to
find the tool appropriate for your particular implementation.
Dirent.h for
UNIX typically or FindFirstFile, etc... for Windoze. Ask in a
programming
group for the particular OS.

 
Reply With Quote
 
 
 
 
John
Guest
Posts: n/a
 
      06-26-2009
On Jun 26, 5:10*pm, Ron <(E-Mail Removed)> wrote:
> On Jun 26, 7:43*am, chiku <(E-Mail Removed)> wrote:> Hi,
> > I have collection of files having names like TripIdSegId.src, where
> > TripId and SegId are numeric fields which is part of filename string.
> > Now i want to search file with lowest TripId and SegId from the given
> > directory.

>
> C++ doesn't really give you any way to search directories. * You'll
> have to
> find the tool appropriate for your particular implementation.
> Dirent.h for
> UNIX typically or FindFirstFile, etc... for Windoze. * Ask in a
> programming
> group for the particular OS.


Yes, i forgot to add that i am using UNIX
 
Reply With Quote
 
Michael Doubez
Guest
Posts: n/a
 
      06-26-2009
On 26 juin, 14:13, John <(E-Mail Removed)> wrote:
> On Jun 26, 5:10*pm, Ron <(E-Mail Removed)> wrote:
>
> > On Jun 26, 7:43*am, chiku <(E-Mail Removed)> wrote:> Hi,
> > > I have collection of files having names like TripIdSegId.src, where
> > > TripId and SegId are numeric fields which is part of filename string.
> > > Now i want to search file with lowest TripId and SegId from the given
> > > directory.

>
> > C++ doesn't really give you any way to search directories. * You'll
> > have to
> > find the tool appropriate for your particular implementation.
> > Dirent.h for
> > UNIX typically or FindFirstFile, etc... for Windoze. * Ask in a
> > programming
> > group for the particular OS.

>
> Yes, i forgot to add that i am using UNIX


There is not standard C++ solution.

Under UNIX, you may use the scandir() function of dirent.h: you can
give it a filter function that get only the files with your pattern
and a comparison function (from what you describe: versionsort) that
you can use to sort your files according to the fields.

--
Michael
 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      06-26-2009
On Jun 26, 3:26 pm, Michael Doubez <(E-Mail Removed)> wrote:
> On 26 juin, 14:13, John <(E-Mail Removed)> wrote:


> > On Jun 26, 5:10 pm, Ron <(E-Mail Removed)> wrote:


> > > On Jun 26, 7:43 am, chiku <(E-Mail Removed)> wrote:> Hi,
> > > > I have collection of files having names like
> > > > TripIdSegId.src, where TripId and SegId are numeric
> > > > fields which is part of filename string. Now i want to
> > > > search file with lowest TripId and SegId from the given
> > > > directory.


> > > C++ doesn't really give you any way to search directories.
> > > You'll have to find the tool appropriate for your
> > > particular implementation. Dirent.h for UNIX typically or
> > > FindFirstFile, etc... for Windoze. Ask in a programming
> > > group for the particular OS.


> > Yes, i forgot to add that i am using UNIX


> There is not standard C++ solution.


Not standard, but I think Boost has something which would help
here.

> Under UNIX, you may use the scandir() function of dirent.h:
> you can give it a filter function that get only the files with
> your pattern and a comparison function (from what you
> describe: versionsort) that you can use to sort your files
> according to the fields.


Under Unix, the simplest solution is to read from a pipe from
ls. Since ls returns its values sorted, you don't have to
search beyond the first entry.

--
James Kanze (GABI Software) email:(E-Mail Removed)
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Is it possible to let a virtual file created by cStringIO havea filename so that functions can read it by its filename? Steven Howe Python 0 01-14-2011 10:32 PM
File.fnmatch? doesn't distinguish between .filename and ./filename ? Stefano Crocco Ruby 0 11-14-2008 10:48 AM
splitting an XML file on the basis on basis of XML tags bijeshn@gmail.com Python 14 04-08-2008 04:26 AM
Arithmetic overflow error converting numeric to data type numeric. darrel ASP .Net 4 07-19-2007 09:57 PM
check if string contains numeric, and check string length of numeric value ief@specialfruit.be C++ 5 06-30-2005 01:08 PM



Advertisments