Martin Barreda
asked on
Get file date & hour from NMFTP
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&attribut tes
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
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&attribut
List;
Name1stFile := FTPDirectoryList.Name[0];
Date1stFile := FTPDirectoryList.ModifDate
StrToDateTime(Date1stFile)
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
ASKER
I read the code and it seems to work but... what is TParser??
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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(Month
Result := Month < 13;
end;
begin
StringStream := TStringStream.Create(S);
try
Parser := TParser.Create(StringStrea
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;