🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
4 messages
4 total messages Started by DeKayA Tue, 08 Apr 2003 18:55
get file specs
#17083
Author: DeKayA
Date: Tue, 08 Apr 2003 18:55
11 lines
1006 bytes
Hi;
Can someone show me how to retrieve a files specifications:
by that I mean:

Modified date and time
  and    File size.

The file is sitting in a filelistbox.

Thanks
DeKayA
Re: get file specs
#17084
Author: Ed Mulroy [TeamB]
Date: Tue, 08 Apr 2003 19:32
14 lines
1298 bytes
Look at the functions FindFirstFile and FindClose.

.  Ed

gave_no_name wrote in message
> news:3e931a5f.198205@forums.inprise.com...
>
> Can someone show me how to retrieve a files
> specifications: by that I mean:
>
> Modified date and time
>   and    File size.
>
> The file is sitting in a filelistbox.
Re: get file specs
#17095
Author: DeKayA
Date: Wed, 09 Apr 2003 03:25
57 lines
2348 bytes
Surely there is a cleaner way...
void __fastcall TVIPForm::GetFileSpecs(String Path)
{   //Surely there is a better way...
  String FileSize;
  String DatenTime;
  int Year;
  int Month;
  int Day;
  int Hour;
  int Min;
  int Sec;

  if(Path.IsEmpty()) //true if the AnsiString is empty.
    return "No File Found";

  TSearchRec sr; //int Time, int Size int Attr, AnsiString Name, int
ExcludeAttr, int FindHandle, _WIN32_FIND_DATAA FindData
  if(FindFirst(Path , faAnyFile, sr) == 0)
    {
      FileSize = IntToStr(sr.Size);
      DatenTime = sr.Time;    //Need to learn how to extract
    }

  FindClose(sr);



 //All this to get the Date & Time..........

   FILE *stream;
   std::ftime ft;

   if ((stream = fopen(Path.c_str(), "r")) == NULL)
   {
       return;  //  Cannot open output file.
   }

   getftime(fileno(stream), &ft); //fileno is handle of stream

   Year  = ft.ft_year+1980;
   Month = ft.ft_month;
   Day   = ft.ft_day;

   Hour = ft.ft_hour;
   Min  = ft.ft_min;
   Sec  = ft.ft_tsec *2;

   fclose(stream);

   MessageBar->Text = "  " + FileSize + " Bytes    " + IntToStr(Month)
+ "/" + IntToStr(Day) + "/" + IntToStr(Year) + "  " + IntToStr(Hour) +
":" + IntToStr(Min) + ":" + IntToStr(Sec);

return;
}

//============================================================
Re: get file specs
#17103
Author: user
Date: Wed, 09 Apr 2003 11:45
27 lines
1719 bytes
DeKayA@bellsouth.net wrote:
> Surely there is a cleaner way...
> 
FindFirstFile returns lots of file specs:

WIN32_FIND_DATA ffd;
HANDLE hff = FindFirstFile(Path.c_str(), &ffd);
if (INVALID_HANDLE_VALUE != hff)
{
     // do something with the fields in ffd...
     FindClose(hff);
}

To be specific:

typedef struct _WIN32_FIND_DATA { // wfd
     DWORD dwFileAttributes;
     FILETIME ftCreationTime;
     FILETIME ftLastAccessTime;
     FILETIME ftLastWriteTime;
     DWORD    nFileSizeHigh;
     DWORD    nFileSizeLow;
     DWORD    dwReserved0;
     DWORD    dwReserved1;
     TCHAR    cFileName[ MAX_PATH ];
     TCHAR    cAlternateFileName[ 14 ];
} WIN32_FIND_DATA;
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads