从一个url串中解析出文件名

去MSDN搜索“netget”,看看
//
// routine to simulate C runtime splitpath
//
// rules
// 1)    a file ALWAYS has an extension
// 2)    from http:, ftp:, gopher:, etc to last / is the URL 'path'
//
// URL                                    Protocol    path                subdir        file
// http://www.msn.com                    http:        //www.msn.com/
// http://www.msn.com/                    http:        //www.msn.com/
// http://www.msn.com/abc                http:        //www.msn.com/        abc/
// http://www.msn.com/abc/                http:        //www.msn.com/        abc/
// http://www.msn.com/trio.htm            http:        //www.msn.com/                    trio.htm
// http://www.msn.com/abc/trio.htm        http:        //www.msn.com/        abc/        trio.htm
//
void CNetGet::MyInternetSplitPath(LPSTR pURLBase, LPSTR pUserURL, LPSTR pUserProtocol, LPSTR pUserPath, LPSTR pUserSubdir, LPSTR pUserFilename)
    {
    char pURL[_MAX_PATH];
    char pCompleteURL[_MAX_PATH];
    char pProtocol[_MAX_PATH];
    char pPath[_MAX_PATH];
    char pSubdir[_MAX_PATH];
    char pFilename[_MAX_PATH];
    char pBuffer[_MAX_PATH];
    LPSTR pPtr;
    int n;
    DWORD dwSize;

    // set defaults
    strcpy(pProtocol, "");
    strcpy(pPath, "");
    strcpy(pSubdir, "");
    strcpy(pFilename, "");

    // get copy of URL parameter
    dwSize = _MAX_PATH;
    InternetCombineUrl(
        pURLBase,
        pUserURL,
        pCompleteURL,
        &dwSize,
        ICU_DECODE);
    strcpy(pURL, pCompleteURL);

    // strip off protocol if given
    pPtr = strchr(pURL, ':');
    if (pPtr)
        {
        n = pPtr - pURL + 1;
        strncpy(pProtocol, pURL, n);
        *(pProtocol + n) = '\0';
        strcpy(pURL, pCompleteURL + n);
        }

    // find path
    pPtr = pURL;
    if (strncmp(pURL, "//", 2) == 0)
        {
        pPtr = pURL + 2;
        }
    pPtr = strchr(pPtr, '/');
    if (pPtr)
        {
        n = pPtr - pURL + 1;
        strncpy(pPath, pURL, n);
        *(pPath + n) = '\0';
        strcpy(pBuffer, pPtr + 1);
        strcpy(pURL, pBuffer);
        }

    // find subdir
    pPtr = strrchr(pURL, '/');
    if (pPtr)
        {
        strcpy(pSubdir, pURL);
        n = pPtr - pURL + 1;
        *(pSubdir + n) = '\0';
        strcpy(pFilename, pPtr + 1);
        }

    strcpy(pUserProtocol, pProtocol);
    strcpy(pUserPath, pPath);
    strcpy(pUserSubdir, pSubdir);
    strcpy(pUserFilename, pFilename);

    return;
    }


你可能感兴趣的:(File)