Hello,

I need to find all files, in a specific directory, that there names starts
with a specific prefix and end with a specific extension.

For example:
The directory to look in = "C:\Temp"
The files to look for in the directory = "ABCD*.nbr"

How do I accomplish that using native (unmanaged) C++?


-------
Thanks
Sharon

Re: How to find files using only part of the files name? by Alex

Alex
Thu Dec 13 05:12:09 PST 2007

"Sharon" wrote:
> I need to find all files, in a specific directory, that
> there names starts
> with a specific prefix and end with a specific extension.

Win32 API: FindFirstFile, FindNextFile, FindClose
CRT: _findfirst, _findnext, _findclose

Alex



Re: How to find files using only part of the files name? by Ulrich

Ulrich
Thu Dec 13 05:14:09 PST 2007

Sharon wrote:
> I need to find all files, in a specific directory, that there names starts
> with a specific prefix and end with a specific extension.
>
> For example:
> The directory to look in = "C:\Temp"
> The files to look for in the directory = "ABCD*.nbr"
>
> How do I accomplish that using native (unmanaged) C++?

C++ itself doesn't have an directory management (and even the file
management is rudimentary), so you will have to use the win32 API to get to
this goal here. For that, take a look at FindFirstFile().

Uli


Re: How to find files using only part of the files name? by David

David
Thu Dec 13 05:22:24 PST 2007


"Sharon" <SharonG@newsgroups.nospam> wrote in message
news:216A9E10-BC0B-4141-94B8-B19615A07CB1@microsoft.com...

> I need to find all files, in a specific directory, that there names starts
> with a specific prefix and end with a specific extension.
>
> For example:
> The directory to look in = "C:\Temp"
> The files to look for in the directory = "ABCD*.nbr"
>
> How do I accomplish that using native (unmanaged) C++?

CString sPathSpec( _T( "c:\\temp\\abcd*.nbr") );
WIN32_FIND_DATA Data;
HANDLE hFindFile;

hFindFile = FindFirstFile( sPathSpec, &Data );

if( hFindFile!=INVALID_HANDLE_VALUE )
{

do
{
/ / What you like with the contents of "Data"

} while( FindNextFile( hFindFile, &Data ) );

FindClose(hFindFile);
}


Dave

--
David Webber
Author of 'Mozart the Music Processor'
http://www.mozart.co.uk
For discussion/support see
http://www.mozart.co.uk/mozartists/mailinglist.htm


Re: How to find files using only part of the files name? by Alex

Alex
Thu Dec 13 08:45:57 PST 2007

"David Webber" wrote:
> CString sPathSpec( _T( "c:\\temp\\abcd*.nbr") );
> WIN32_FIND_DATA Data;
> HANDLE hFindFile;
>
> hFindFile = FindFirstFile( sPathSpec, &Data );
> [...]

Actually, if you use MFC already, then there is handy
`CFileFind' class, which encapsulates the details like
`WIN32_FIND_DATA' etc.

Alex



Re: How to find files using only part of the files name? by SharonG

SharonG
Thu Dec 13 11:25:02 PST 2007


Thanks a lot to you all (-;

--
Thanks
Sharon

Re: How to find files using only part of the files name? by David

David
Fri Dec 14 01:21:08 PST 2007


"Alex Blekhman" <tkfx.REMOVE@yahoo.com> wrote in message
news:Oh2EkeaPIHA.5208@TK2MSFTNGP04.phx.gbl...
> "David Webber" wrote:
>> CString sPathSpec( _T( "c:\\temp\\abcd*.nbr") );
>> WIN32_FIND_DATA Data;
>> HANDLE hFindFile;
>>
>> hFindFile = FindFirstFile( sPathSpec, &Data );
>> [...]
>
> Actually, if you use MFC already, then there is handy `CFileFind' class,
> which encapsulates the details like `WIN32_FIND_DATA' etc.

Thanks. The original is so simple that I never thought to look for an MFC
class to do it! Next time I need it, I'll try it out.

Dave
--
David Webber
Author of 'Mozart the Music Processor'
http://www.mozart.co.uk
For discussion/support see
http://www.mozart.co.uk/mozartists/mailinglist.htm