Programming 版 (精华区)

发信人: pzc (不过如此), 信区: Programming
标  题: 枚举网络所有文件
发信站: 哈工大紫丁香 (2002年03月16日21:31:39 星期六), 站内信件

void CBDlg::OnButton1()
{
    file.Open("t.txt",CFile::modeWrite|CFile::modeRead|CFile::modeCreate);
    this->EnumNet(NULL);
    file.Close();
}
void CBDlg::EnumNet(NETRESOURCE *pNetResource)
{
HANDLE hEnum;
DWORD ret;
DWORD Count = 0xFFFFFFFF;
DWORD BufferSize = 16*1024;
LPVOID Buffer = new char[16*1024];
DWORD Len;
ret=WNetOpenEnum (RESOURCE_GLOBALNET,RESOURCETYPE_DISK,0,pNetResource,&hEnum
);
if(ret!=NO_ERROR) return;
ret=WNetEnumResource( hEnum, &Count, Buffer, &BufferSize );
if(ret!=NO_ERROR) return;
pNetResource = (NETRESOURCE*)Buffer;
Len=BufferSize/sizeof(NETRESOURCE);
for ( unsigned int i = 0; i < Count; i++, pNetResource++ )
{
    if(RESOURCEUSAGE_CONTAINER==(pNetResource->dwUsage&RESOURCEUSAGE_CONTAIN
ER))
    {
          this->EnumNet(pNetResource);
    }
    else
    {
          EnumDir(pNetResource->lpRemoteName);
    }
}
delete Buffer;
WNetCloseEnum( hEnum );
return;
}
void  CBDlg::EnumDir(char *CurDir)
{
HANDLE hSearch;
WIN32_FIND_DATA wsd;
char DirofFile[250];
BOOL bFind;
strcpy(DirofFile,CurDir);
strcat(DirofFile,"\\*.*");
hSearch = FindFirstFile(DirofFile,&wsd);
if(hSearch<=0)
{
    return;
}
do{
bFind = FindNextFile(hSearch,&wsd);
if(bFind && strcmp(wsd.cFileName,".") && strcmp(wsd.cFileName,".."))
{
   if(wsd.dwFileAttributes==FILE_ATTRIBUTE_DIRECTORY)
   {
            
       strcpy(DirofFile,CurDir);
       strcat(DirofFile,"\\");
       strcat(DirofFile,wsd.cFileName);
       EnumDir(DirofFile);
    }
   else
   {
       file.WriteString(CurDir);
       file.WriteString("\\");
       file.WriteString(wsd.cFileName);
       file.WriteString("\r\n");
   }
}
}while(bFind);
FindClose(hSearch);
}

--
※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 202.118.236.144]
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:8.258毫秒