-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCreateFileName.cpp
More file actions
executable file
·28 lines (22 loc) · 973 Bytes
/
CreateFileName.cpp
File metadata and controls
executable file
·28 lines (22 loc) · 973 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "CreateFileName.h"
#include <ctime>
#include <cstdio>
#pragma warning( disable: 4996 )
///////////////////////////////////////////////////////////////////////
// Create a unique file name from the date and time
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*static*/ std::string CreateFileName::Create( const std::string& prefix, const std::string& extension )
//---------------------------------------------------------------------
{
const time_t now = time(NULL);
char buft[256];
const int len = sizeof(buft);
for ( int i=0; i<len; ++i ) buft[i] = '\0';
strftime( buft, sizeof(buft), "%Y-%m-%d.%X", localtime(&now) );
for ( int i=0; i<len; ++i )
{
// blanks are irritating and colons are illegal
if ( buft[i] == ' ' || buft[i] == ':' ) buft[i] = '_';
}
return( prefix + "_" + std::string( buft ) + "." + extension );
}