//--------------------------------------------------------------------------- // Global Functions //--------------------------------------------------------------------------- bool dir_isvaliddir(LPSTR path) //Check valid directory { //TODO: Add your source code here DWORD dwAttrib; dwAttrib = GetFileAttributes(path); if (dwAttrib == -1) { return( false ); } if (dwAttrib & FILE_ATTRIBUTE_DIRECTORY) { return( true ); } return( false ); } //--------------------------------------------------------------------------- void scandir(char * dirname) { //TODO: Add your source code here DIR *dir; struct dirent *ent; //entities char tmpstr[255]; char tmpstr1[80]; double filesize; TDateTime FileDT; int NF = 0; if ((dir = opendir(dirname)) == NULL) { sprintf(tmpstr, "Unable to open '%s' directory.\n", dirname ); ShowMessage( tmpstr ); exit(1); } while ((ent = readdir(dir)) != NULL) { //debug_Print(ent->d_name); if( strcmp(ent->d_name, "." ) == 0 ) { //debug_Print("Current directory !!"); } else if( strcmp(ent->d_name, ".." ) == 0 ) { //debug_Print("Parent directory !!"); } else { /* sprintf(tmpstr,"%s\\%s",dirname,ent->d_name); this->WorkStr->Caption = tmpstr; */ sprintf(tmpstr,"%s\\%s",dirname,ent->d_name); if (FileExists(tmpstr)) { filesize = (double (dir_getfilesize( tmpstr ))) / 1024.0; FileDT = dir_getfiledatetime( tmpstr ); //debug_Print(tmpstr); if( is_supportedFileExt( tmpstr ) ) { sprintf( tmpstr1,"%s (%8.1lfkb)", ent->d_name, filesize); this->AddIcon( tmpstr, tmpstr1, NF ); NF++; } } } } if (closedir(dir) != 0) { //debug_Print("Unable to close directory"); sprintf(tmpstr, "Unable to close '%s' directory.\n", dirname ); ShowMessage(tmpstr ); } } //--------------------------------------------------------------------------- bool is_supportedFileExt(AnsiString theFilePath) { //TODO: Add your source code here AnsiString temp; temp = theFilePath.SubString( theFilePath.Length()-2, 3 ); //temp = temp.UpperCase(); if( temp == "avi" || temp == "AVI" ) { return( true ); } return( false ); } //--------------------------------------------------------------------------- long dir_getfilesize(LPSTR path) { //TODO: Add your source code here int fh; OFSTRUCT os; long size; fh = OpenFile(path, &os, OF_READ|OF_SHARE_DENY_NONE); if (fh == -1) { return(0); } size = GetFileSize( (HANDLE) fh, NULL); _lclose(fh); return(size); } //--------------------------------------------------------------------------- TDateTime dir_getfiledatetime(LPSTR path) { //TODO: Add your source code here int fh; OFSTRUCT os; fh = OpenFile(path, &os, OF_READ|OF_SHARE_DENY_NONE); if (fh == -1) { return(0); } FILETIME ftCreate, ftAccess, ftWrite; SYSTEMTIME stUTC, stLocal; // Retrieve the file times for the file. if (!GetFileTime((HANDLE) fh, &ftCreate, &ftAccess, &ftWrite)) return FALSE; // Convert the last-write time to local time. FileTimeToSystemTime(&ftWrite, &stUTC); SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal); char tempstr[80]; // Build a string showing the date and time. wsprintf(tempstr, "%02d/%02d/%d %02d:%02d:%02d", stLocal.wYear, stLocal.wMonth, stLocal.wDay, stLocal.wHour, stLocal.wMinute, stLocal.wSecond ); _lclose(fh); return( StrToDateTime(tempstr) ); } //--------------------------------------------------------------------------- bool isNum( int *aNum, AnsiString aNumStr) { char *tempstr = aNumStr.c_str(); int len = strlen( tempstr ); *aNum = -1; if( aNumStr.IsEmpty() ) { return false; } for( int i=0; i