/* windows */
#include <stdio.h>
#include <string.h>
#include <windows.h>
#include <Shlobj.h>
int _GetDir(char *Path)
{
char *Title = "选择文件夹";
BROWSEINFO bi;
bi.hwndOwner = 0;
bi.pidlRoot = NULL;
bi.pszDisplayName = Path;
bi.lpszTitle = Title;
bi.ulFlags = BIF_RETURNONLYFSDIRS;
bi.lpfn = NULL;
bi.iImage = 0;
bi.lParam = 0;
PIDLIST_ABSOLUTE pIDList;
pIDList = SHBrowseForFolder(&bi);
if (pIDList)
{
SHGetPathFromIDList(pIDList, Path);
return 1;
}
return 0;
}
int main(void)
{
char FileExtensions[PATH_MAX];
if (!_GetDir(FileExtensions))
return 0;
if (FileExtensions[strlen(FileExtensions)-1] != '\\')
strcat(FileExtensions, "\\");
printf("文件夹:%s\n", FileExtensions);
strcat(FileExtensions, "*.*");
WIN32_FIND_DATA FindData;
HANDLE hFindFile = FindFirstFile(FileExtensions, &FindData);
if (hFindFile == INVALID_HANDLE_VALUE)
return 0;
int len, maxlen=0, minlen=PATH_MAX;
char maxname[PATH_MAX], minname[PATH_MAX];
do
{
if (FindData.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY)
{
len = strlen(FindData.cFileName);
if (len > maxlen)
{
maxlen = len;
strcpy(maxname, FindData.cFileName);
}
else if (len < minlen)
{
minlen = len;
strcpy(minname, FindData.cFileName);
}
printf("%s\n", FindData.cFileName);
}
}while (FindNextFile(hFindFile, &FindData));
FindClose(hFindFile);
if (maxlen != 0)
{
printf("\n最长文件名:%s\n", maxname);
printf("最短文件名:%s\n", minname);
}
}