How to get the program running path, named file by system time

Source: Internet
Author: User

I haven't updated my blog for a long time, so I still have no patience. Obtain the current path of the running program and the file named after the system time, and paste it here for reference!

Hresult getcurrentpath (string & strpath)
{
Tchar sfilename [_ max_path];
Tchar sfullname [_ max_path];
Tchar sdir [_ max_dir];

If (! (& Strpath ))
Return e_pointer;
Getmodulefilename (null, sfilename, _ max_path );
_ Splitpath (sfilename, sfullname, sdir, null, null );

Strpath = sfullname;
Strpath + = sdir;

Return s_ OK;

}

The nportnum can be used as sequential numbers.

Hresult getfilename (INT nportnum, string & strfilename)
{
Systemtime st;
Char filename [1024];
If (! (& Strfilename ))
Return e_pointer;

If (nportnum <0)
Return e_invalidarg;

Getsystemtime (& St );

ITOA (nportnum, filename, 10 );
Strfilename = strfilename + filename + "_";
ITOA (St. wyear, filename, 10 );
Strfilename = strfilename + filename + "_";
ITOA (St. wmonth, filename, 10 );
Strfilename = strfilename + filename + "_";
ITOA (St. wday, filename, 10 );
Strfilename = strfilename + filename + "_";
ITOA (St. whour, filename, 10 );
Strfilename = strfilename + filename + "_";
ITOA (St. wminute, filename, 10 );
Strfilename = strfilename + filename + "_";
ITOA (St. wsecond, filename, 10 );
Strfilename + = filename;
Strfilename + = ". txt ";

Return s_ OK;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.