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

Discussion in 'C++' started by chiku, Jun 26, 2009.

  1. chiku

    chiku Guest

    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
     
    chiku, Jun 26, 2009
    #1
    1. Advertising

  2. chiku

    Ron Guest

    On Jun 26, 7:43 am, chiku <> 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.
     
    Ron, Jun 26, 2009
    #2
    1. Advertising

  3. chiku

    John Guest

    On Jun 26, 5:10 pm, Ron <> wrote:
    > On Jun 26, 7:43 am, chiku <> 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
     
    John, Jun 26, 2009
    #3
  4. On 26 juin, 14:13, John <> wrote:
    > On Jun 26, 5:10 pm, Ron <> wrote:
    >
    > > On Jun 26, 7:43 am, chiku <> 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
     
    Michael Doubez, Jun 26, 2009
    #4
  5. chiku

    James Kanze Guest

    On Jun 26, 3:26 pm, Michael Doubez <> wrote:
    > On 26 juin, 14:13, John <> wrote:


    > > On Jun 26, 5:10 pm, Ron <> wrote:


    > > > On Jun 26, 7:43 am, chiku <> 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:
    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
     
    James Kanze, Jun 26, 2009
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Sm9l?=

    Extract filename from a filename typed by user

    =?Utf-8?B?Sm9l?=, Aug 23, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,060
    Travis Murray
    Aug 24, 2004
  2. Replies:
    1
    Views:
    1,570
    Roland de Ruiter
    Jun 15, 2006
  3. Ed
    Replies:
    10
    Views:
    46,502
    alok000707
    Jul 13, 2010
  4. Replies:
    14
    Views:
    557
    bijeshn
    Apr 8, 2008
  5. Stefano Crocco
    Replies:
    0
    Views:
    154
    Stefano Crocco
    Nov 14, 2008
Loading...

Share This Page