Searching a Win-Directory for specific files

Okay so for school, I'm supposed to write a short programm that searches a given directory for files that have a name-tag thats like "AA[...].dat", "AA[...].sel", "AA[...].ilk" and "AA[...].out". There are a lot of other files in there, but I'm only interested in those that start with "AA".
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <windows.h>
#include <iostream>
int main(int argc, char* argv[])
{
	WIN32_FIND_DATA search_data;

	memset(&search_data, 0, sizeof(WIN32_FIND_DATA));

        HANDLE handle = FindFirstFile("\\\\P_SERVER\\Input\\*.dat*", &search_data);
	

	while (handle != INVALID_HANDLE_VALUE)
	{
		std::cout << search_data.cFileName << " --- " << search_data.nFileSizeHigh << "\n";
	
		if (FindNextFile(handle, &search_data) == FALSE)
			break;
	}

	//Close the handle after use or memory/resource leak
	FindClose(handle);
	system("pause");
	return 0;
}


This is what i've come up with so far, it perfectly displays all .sel files in that folder.
But how do i make it search only for files that start with "AA"? And how can i implement a comparison, so it only displays the files that are not complete? (every file starting with "AA" has .dat, .sel, .ilk and .out) Only those files that have only a .dat in this folder are what I'm looking for.

Any helps/tips/critic on the code is appreciated!
1
2
3
// HANDLE handle = FindFirstFile("\\\\P_SERVER\\Input\\*.dat*", &search_data);
HANDLE handle = FindFirstFile( "\\\\P_SERVER\\Input\\AA*.dat", &search_data); // starts with 'AA', and ends in '.dat'
// note: AA*.dat* - starts with 'AA', and contains '.dat' 
Last edited on
Wow, now i feel dumb, didn't think it was that easy, thanks!
On another note, how do i write the creation time of that file into a .csv?
 
f << search_data.ftCreationTime << ';'; 

That refuses to work.

I want to be able to make an Excel-List where the .dat are on Column A and their respective Creation Time on Column B
1
2
3
4
5
6
7
8
9
10
11
12
13
std::string to_string( FILETIME ftime ) // ISO format, time zone designator Z == zero (UTC)
{
    SYSTEMTIME utc ;
    ::FileTimeToSystemTime( std::addressof(ftime), std::addressof(utc) );

    std::ostringstream stm ;
    const auto w2 = std::setw(2) ;
    stm << std::setfill('0') << std::setw(4) << utc.wYear << '-' << w2 << utc.wMonth
        << '-' << w2 << utc.wDay << ' ' << w2 << utc.wYear << ' ' << w2 << utc.wHour
        << ':' << w2 << utc.wMinute << ':' << w2 << utc.wSecond << 'Z' ;

    return stm.str() ;
}

http://rextester.com/DDL72539
Topic archived. No new replies allowed.