Function FileAttrIs(const FPath:String):TFileAttr;
Var
F:LongInt;
begin
F := FileGetAttr(FPath);
IF(F<>-1)Then
begin
IF(F AND FaReadOnly)<>0Then Result := ReadOnly;
IF(F AND FaSysFile)<>0Then Result := SysFile;
IF(F AND FaVolumeID)<>0Then Result := DLabel;
IF(F AND FaDirectory)<>0Then Result := Dir;
IF(F AND FaHidden)<>0Then Result := Hidden;
IF(F AND FaArchive)<>0Then Result := Archive;
end Else Result := FError;
end;
And what about files that are read-only, hidden, archived and have the systemattribute set?
Your function will return Archive
Also for a filename with no attribute set the function will return FError.
Function ReturnFileData(const FPAth:String):DataHolder;
Var FileVar:TextFile;
begin
AssignFile(FileVar,FPath);
Reset(FileVar);
Repeat
Readln(FileVar,Result);
until(EoF(FileVar));
CloseFile(FileVar);
end;
Result will always hold the last line of the textfile.
Probably not what you want?
Function CountFileLines(const FPath:String):LongInt;
Var
FileVar:TextFile;
Counter:LongInt;
ReadStr:DataHolder;
begin
Counter := 0;
AssignFile(FileVar,FPath);
Reset(FileVar);
Repeat
Readln(FileVar,ReadStr);
Inc(Counter);
until(EoF(FileVar));
CloseFile(FileVar);
Result := Counter;
end;
The result will be 1 for an empty file. Doesn't sound right to me.
Hint: change the "repeat until" loop to a "while do" loop.
In general.
Be aware that in none of your functions/procedures do you handle file IO errors.
For better readability you might want to indent the repeat/until and while/do loops.
Bart