SetDirectory(char *DirName)//如SetDirectory("c://aaa")
{
CFileFind tempFind;
char tempFileFind[MAX_PATH];
sprintf(tempFileFind,"%s//*.*",DirName);
BOOL IsFinded=(BOOL)tempFind.FindFile(tempFileFind);
while(IsFinded)
{
IsFinded=(BOOL)tempFind.FindNextFile();
if(!tempFind.IsDots())
{
char foundFileName[MAX_PATH];
strcpy(foundFileName,tempFind.GetFileName().GetBuffer(MAX_PATH));
if(tempFind.IsDirectory())
{
char tempDir[MAX_PATH];
sprintf(tempDir,"%s//%s",DirName,foundFileName);
SetDirectory(tempDir);
}
else
{
char tempFileName[MAX_PATH];
sprintf(tempFileName,"%s//%s",DirName,foundFileName);
DWORD dWold;
dWold=::GetFileAttributes(tempFileName);
dWold&=~FILE_ATTRIBUTE_READONLY;
::SetFileAttributes(tempFileName,dWold);
}
}
}
tempFind.Close();
}
{
CFileFind tempFind;
char tempFileFind[MAX_PATH];
sprintf(tempFileFind,"%s//*.*",DirName);
BOOL IsFinded=(BOOL)tempFind.FindFile(tempFileFind);
while(IsFinded)
{
IsFinded=(BOOL)tempFind.FindNextFile();
if(!tempFind.IsDots())
{
char foundFileName[MAX_PATH];
strcpy(foundFileName,tempFind.GetFileName().GetBuffer(MAX_PATH));
if(tempFind.IsDirectory())
{
char tempDir[MAX_PATH];
sprintf(tempDir,"%s//%s",DirName,foundFileName);
SetDirectory(tempDir);
}
else
{
char tempFileName[MAX_PATH];
sprintf(tempFileName,"%s//%s",DirName,foundFileName);
DWORD dWold;
dWold=::GetFileAttributes(tempFileName);
dWold&=~FILE_ATTRIBUTE_READONLY;
::SetFileAttributes(tempFileName,dWold);
}
}
}
tempFind.Close();
}
博客给出了一段C语言代码,定义了SetDirectory函数,用于设置指定目录及其子目录下文件的属性。函数会遍历目录中的文件和子目录,若为子目录则递归调用自身,若为文件则去除其只读属性。
487

被折叠的 条评论
为什么被折叠?



