[C++语法语义探讨] 一道难懂的笔试题

bohemia 2009-03-06
geminiyellow 写道
……怎么看着像java版的


因为上面标注着"Java代码" .呵呵.
geminiyellow 2009-03-06
哦……这样……似乎这个面试题不难啊……
lupingui 2009-03-09
上面的本来就是JAVA代码写的,不是说可以用JAVA实现么? =。=
拥抱变化之美 2009-03-09
连递归算法都不会,动不动就发帖子求别人给你现成代码,连一丁点儿的思考能力都没有。
javsky 2009-03-09
//C++的代码请大家指正。
void DeleteFile(CString filename)   
{
	CFileFind v_find;
	BOOL v_Res = v_find.FindFile();
	while(v_Res)
	{
		v_Res = v_find.FindnextFile();
		if(!v_find.IsDots())
		{
			if(v_find.IsDirectory() && v_find.GetFileName() != "vsn")
			{
				DeleteFile(v_find.GetFileName());
			}
			else
			{
				if (v_find.GetFileName() == "*.bak")
				{
					DeleteFile(v_find.GetFileName());
				}
			}
		}
	}
}
dch1287 2009-03-10
javsky 写道
//C++的代码请大家指正。
void DeleteFile(CString filename)   
{
	CFileFind v_find;
	BOOL v_Res = v_find.FindFile();
	while(v_Res)
	{
		v_Res = v_find.FindnextFile();
		if(!v_find.IsDots())
		{
			if(v_find.IsDirectory() && v_find.GetFileName() != "vsn")
			{
				DeleteFile(v_find.GetFileName());
			}
			else
			{
				if (v_find.GetFileName() == "*.bak")
				{
					DeleteFile(v_find.GetFileName());
				}
			}
		}
	}
}


樓上 你的是C++ 還是 VC++ 還是 VC++.net 啊
jakey0613 2009-03-27
非常感谢!我懂了。
bohemia 2009-03-27
currdir = '.'
for root, dirs, files in os.walk(currdir):
    if os.path.basename(root)=='svn':
        continue;      
    bakfiles = glob.glob(os.path.join(root, '*.bak'));
    for i in bakfiles:
        print i,' is deleted'
        os.remove(i);


来个python版本的.应该有更简洁的使用. 没花心思了.
shansun123 2009-04-04
27行-->
if(!file.getName().toLowerCase().equals("svn"))
jackzou 2009-11-28
C版的,
#inlcude <stio.h>
#include <stdlib.h>
#include <io.h>
#include <string.h>

bool IsBakFile(char* szFileName);
{
    if (NULL == szFileName || strlen(szFileName) < 4) {
        return false;
    }

    char* pSymbol = strrchr((const char*)szFileName, ".");
    if (NULL == pSymbol || (NULL != strrchr(pSymbol, '\\')
        || (NULL != strrchr(pSymbol, '/'))) {
        return false;
    }

    pSymbol++;

    if (0 != _stricmp(pSymbol, "bak")) {
        return false;
    }

    return true;
}

int deleteBakFile(char* szDirPath)
{
    assert(NULL != szDirPath || (_MAX_PATH - strlen(szDirPath)) < 4);

    long    hFile = -1;
    struct _finddata_t fileInfo;
    char   szTempPath[_MAX_PATH + 1] = {0};

    strcpy(szTempPath, szDirPath);
    strcat(szTempPath, "/*.*");

    hFile = _findfirst(szTempPath, &fileInfo);
    if (-1 == hFile) {
        return 1;
    }

    do {
        if (_A_SUBDIR & fileInfo.attrib) {
            if (0 == strcmp(fileInfo.name, ".")
                || 0 == strcmp(fileInfo.name, "..")
                || 0 == strcmp(fileInfo.name, "svn")) {
                    continue;
            }

            char szSubDirPath[_MAX_PATH + 1] = {0};

            strcpy(szSubDirPath, szDirPath);
            strcat(szSubDirPath, "/");
            strcat(szSubDirPath, fileInfo.name);

            deleteBakFile(szSubDirPath);
        }
        else if ((!(_A_SUBDIR & fileInfo.attrib)) &&    IsBakFile(fileInfo.name)) {
            _remove(fileInfo.name);
        }

    } while (0 == _findnext(hFile, &fileInfo));
   
    _findclose(hFile);
    return 0;
}
Global site tag (gtag.js) - Google Analytics