#include "stl.h"
#include <windows.h>
#define _WIN32_WINNT 0x0501
bool CheckExtendName(const char *pszStr,const char *pszExd)//后缀名比较
{
char *pt=(char*)pszStr;
pt +=strlen(pszStr);
while(pt!=(char*)pszStr && *pt-- !='.');
if(*(++pt) !='.')
return false;
pt++;
//将比较字符和传入的后缀名转为小写
if(strcmp(_strlwr(pt),_strlwr((char *)pszExd))==0)
{
return true;
}
else
{
return false;
}
}
int main(int argc, char *argv[])
{
WIN32_FIND_DATA FindFileData;
PicOrder the_app;//排序
stu st;//需加入的对象
HANDLE hFind = INVALID_HANDLE_VALUE;
char DirSpec[MAX_PATH]; // directory specification
DWORD dwError;
printf ("Target directory is %s.\n", argv[1]);
strncpy (DirSpec, argv[1], strlen(argv[1])+1);
strncat (DirSpec, "\\*", 3);
hFind = FindFirstFile(DirSpec, &FindFileData);
if(CheckExtendName(FindFileData.cFileName,"jpg")==true)
{
st.name=string(FindFileData.cFileName);
st.size=FindFileData.nFileSizeLow;
st.time.dwHighDateTime=FindFileData. ftLastWriteTime.dwHighDateTime;
st.time.dwLowDateTime=FindFileData. ftLastWriteTime.dwLowDateTime;
the_app.PicJoin(st);
}
if (hFind == INVALID_HANDLE_VALUE)
{
printf ("Invalid file handle. Error is %u\n", GetLastError());
return (-1);
}
else
{
while (FindNextFile(hFind, &FindFileData) != 0)
{
printf ("Next file name is %s\n", FindFileData.cFileName);
if(CheckExtendName(FindFileData.cFileName,"jpg")==true)
{
st.name=string(FindFileData.cFileName);
st.size=FindFileData.nFileSizeLow;
st.time.dwHighDateTime=FindFileData. ftLastWriteTime.dwHighDateTime;
st.time.dwLowDateTime=FindFileData. ftLastWriteTime.dwLowDateTime;
the_app.PicJoin(st);
}
}
dwError = GetLastError();
FindClose(hFind);
if (dwError != ERROR_NO_MORE_FILES)
{
printf ("FindNextFile error. Error is %u\n", dwError);
return (-1);
}
}
the_app.OrderbyName();
int xx=the_app.GetPicNum();
string *p= new string [xx];
the_app.putout(p);
for(int i=0;i<xx;i++)
printf("the name is %s\n",p[i].c_str());
the_app.OrderbySize();
the_app.putout(p);
for(i=0;i<xx;i++)
printf("the name is %s\n",p[i].c_str());
delete []p;
printf("Hello World!");
return 0;
}