kagami01
asked on
how to get the extension in ".txt" with a date format time?
Hello EE,
i have some problem with this code
how to get "myfile-somerandomnumberhe re-Mon_sep _29_21:59: 01_2008.tx t"?
i have some problem with this code
how to get "myfile-somerandomnumberhe
std::stringstream ssFilename; //nuove variabile per uploaddare il file
time( &aclock ); /* Get time in seconds */
newtime = localtime( &aclock ); /* Convert time to struct */
/* tm form */
ssFilename
<< asctime(newtime)
<< "-"
<< "myfile-"
<< acUserName// add user name
<< "-"
<< std::setw(5)
<< std::setfill('0')
<< (rand() % 100000)
<< ".txt";
std::string const & sFilename = ssFilename.str();
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You probably also want to replace the spaces in the filename with underscores after constructing it ...
ASKER
the code abouve here doesn't uploads the file anymore...
Try this code...
// Seed the random-number generator with the current time so that
// the numbers will be different every time we run.
srand( (unsigned)time( NULL ) );
string str_newtime = asctime(newtime) ;
string str_old = " ";
string str_new = "_";
string str_time = str_newtime;
int pos1 = 0;
int pos2 = 0;
while ((pos1 = str_time.find(str_old, pos2)) != string::npos)
{
str_time.replace(pos1, str_old.length(), str_new);
pos2 = pos1+1;
}
ssFilename
<< myfile-
<< (rand() % 100000)
<< "-"
<< "acUserName"// add user name
<< "-"
<< str_time
<< ".txt";
std::string const & sFilename = ssFilename.str();
cout << sFilename.c_str();
cout <<"\n";
Oops typo....sorry please read this as
ssFilename
<< myfile<<"-" //------------------------ >Changed here
<< (rand() % 100000)
<< "-"
<< "acUserName"// add user name
<< "-"
<< str_time
<< ".txt";
ssFilename
<< myfile<<"-" //------------------------
<< (rand() % 100000)
<< "-"
<< "acUserName"// add user name
<< "-"
<< str_time
<< ".txt";
ASKER
i meant it upload the file but the extension is not ".txt"
This version of replace is probably a better fit for replacing all spaces with underscores (in one call) :
http://www.cplusplus.com/reference/algorithm/replace.html
;)
http://www.cplusplus.com/reference/algorithm/replace.html
;)
What is the extn it shows? is there any other "." in the string other than ".txt"
ASKER
i got this file name extension
"myfile-user1-1222785145Tu e Sep 30 16:32:25 2008"
with no .txt extension file
i put here my code again
ps
by the way if i go on my ftp web space i can read the file but i cannot delete it modify it and so on cause it contains some strange symbol
"myfile-user1-1222785145Tu
with no .txt extension file
i put here my code again
ps
by the way if i go on my ftp web space i can read the file but i cannot delete it modify it and so on cause it contains some strange symbol
DWORD WINAPI ftp_upload(LPVOID lpParam)
{
struct tm *newtime;
time_t aclock;
char acUserName[UNLEN + 1];
DWORD dwNameLen = UNLEN + 1;
GetUserName(acUserName,&dwNameLen);
/////////////////////////////////////////////////////////////////////
//this part of code is cool!!!
/////////////////////////////////////////////////////////////////////
HINTERNET hCon, sFtp;
while(true)
{
std::stringstream ssFilename; /
time( &aclock ); /* Get time in seconds */
newtime = localtime( &aclock ); /* Convert time to struct */
/* tm form */
ssFilename
<< "myfile-"
<< acUserName // add user name
<< "-"
<< time(NULL)
<< asctime(newtime)
<< "-"
<< std::setw(5)
<< std::setfill('0')
<< (rand() % 100000)
<< ".txt";
string const sFilename = ssFilename.str();
ASKER
i got the ".txt" extension cnhanging my code like this...see below
and now my file is "lmyfile-user1-12227853870 0041.txt""
i think the problem is the time format
and now my file is "lmyfile-user1-12227853870
i think the problem is the time format
DWORD WINAPI ftp_upload(LPVOID lpParam)
{
struct tm *newtime;
time_t aclock;
char acUserName[UNLEN + 1];
DWORD dwNameLen = UNLEN + 1;
GetUserName(acUserName,&dwNameLen);
/////////////////////////////////////////////////////////////////////
//this part of code is cool!!!
/////////////////////////////////////////////////////////////////////
HINTERNET hCon, sFtp;
while(true)
{
std::stringstream ssFilename;
time( &aclock ); /* Get time in seconds */
newtime = localtime( &aclock ); /* Convert time to struct */
/* tm form */
ssFilename
<< "myfile-"
<< acUserName // add user name
<< "-"
<< time(NULL)
<< std::setw(5)
<< std::setfill('0')
<< (rand() % 100000)
<< ".txt";
string const sFilename = ssFilename.str()
>> i think the problem is the time format
What do you mean ?
Btw, don't you want to replace the spaces with underscores ?
What do you mean ?
Btw, don't you want to replace the spaces with underscores ?
ASKER
yeah because my time format was HH:MM:SS YYYY MM DD
so in ftp webspace the ":" and the " " character are not accepted.
for example i have uploaded the follw file "myfile-12:01:00 2008 10 01"
if i want to change this file name direclty from my ftp webspace ,i got an error as follows "you cannot change the name of this file because the format is not accepted".
Anyway i have already solved the problem.Please see my other asked question.
so in ftp webspace the ":" and the " " character are not accepted.
for example i have uploaded the follw file "myfile-12:01:00 2008 10 01"
if i want to change this file name direclty from my ftp webspace ,i got an error as follows "you cannot change the name of this file because the format is not accepted".
Anyway i have already solved the problem.Please see my other asked question.
Did any of our answers/suggestions helped you in soulving your problem? If yes, I would ask you to close this by assiging points ..Thanks,
DeepuAbrahamK
DeepuAbrahamK