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

C

chiku

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
 
R

Ron

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.
 
J

John

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
 
M

Michael Doubez

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.
 
J

James Kanze

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top