Solved

Get file date & hour from NMFTP

Posted on 2001-08-02
4
378 Views
Last Modified: 2007-12-19
I am using Delphi 5 and NMFTP Component.
I need to get the date of the files in the server.
I want to do something like this:

with NMFTP1 do
  begin
    ParseList := TRUE;
    Connect;
//gets a listing of files,names,dates&attributtes
    List;
    Name1stFile := FTPDirectoryList.Name[0];
    Date1stFile := FTPDirectoryList.ModifDate[0];
    StrToDateTime(Date1stFile); //!!!!FAIL!!!!
end;

The date recovered is in this format "Aug 2 18:08"
But i need something that i can convert to datetime, and of course the year...
It not depends on server configuration because BulletProof FTP get then date by the way in need "02/08/2001 18:08:00" as configured in my machine, so there may be a way...
Thanks to you all
0
Comment
Question by:spk2000ar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 2

Expert Comment

by:SChertkov
ID: 6348179
This is POSIX date convention: for date less 7 month ago
the date be reflected as mon day time
(have in mind current year),
for greater date  format is mon day year.

For decode this date you can try following


const
  Months: array[1..12] of string = (
    'Jan', 'Feb', 'Mar', 'Apr',
    'May', 'Jun', 'Jul', 'Aug',
    'Sep', 'Oct', 'Nov', 'Dec');

function MyDecodeDate(S: String): TDateTime;
var
  Parser: TParser;
  StringStream: TStringStream;
  Month, Day, Year, Hour, Minute: Integer;
  d,m,y: Word;

  function GetMonth: Boolean;
  begin
    Month := 1;
    while not Parser.TokenSymbolIs(Months[Month]) and (Month < 13) do Inc(Month);
    Result := Month < 13;
  end;

begin
  StringStream := TStringStream.Create(S);
  try
    Parser := TParser.Create(StringStream);
    with Parser do
    try
      if not GetMonth then
        raise EConvertError.Create('');
      NextToken;
      Day := TokenInt;
      NextToken;
      Year := TokenInt;
      NextToken;
      if Token = ':' then
        begin
          Hour := Year;
          DecodeDate(Date, y, m, d);
          Year := y;
          NextToken;
          Minute := TokenInt;
          Result := EncodeDate(Year, Month, Day) + EncodeTime(Hour, Minute, 0, 0);
        end
      else
        Result := EncodeDate(Year, Month, Day);
    finally
      Parser.Free;
    end;
  finally
    StringStream.Free;
  end;
end;
0
 
LVL 4

Author Comment

by:spk2000ar
ID: 6349963
I read the code and it seems to work but... what is TParser??
0
 
LVL 4

Author Comment

by:spk2000ar
ID: 6350240
Sorry i found Tparser in classes unit.
I will select your comment as an answer but i need some advice first...
what will happens when the year changes... i still get the new year (says 2002) but the real year will be (2001)???
Thanks
0
 
LVL 2

Accepted Solution

by:
SChertkov earned 200 total points
ID: 6354706
TParser defined in CopyPrsr unit.
If year changes you date represented
as Mon Day Year
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question