1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- unit futils;
- {$mode objfpc}
- {$h+}
- Interface
- Const
- {$ifdef win32}
- PathSeparator='\';
- {$else}
- PathSeparator='/';
- {$endif}
- Function StripTrailingSeparator(Const Dir : String) : String;
- Function AddTrailingSeparator(Const Dir : String) : String;
- Function FileSizeToString(Size: Int64) : String;
- Function FileAttrsToString(FileAttrs : Integer) : String;
- Implementation
- Uses sysutils;
- Function StripTrailingSeparator(Const Dir : String) : String;
-
- Var
- L : Integer;
-
- begin
- Result:=Dir;
- L:=Length(result);
- If (L>1) and (Result[l]=PathSeparator) then
- SetLength(Result,L-1);
- end;
-
- Function AddTraiLingSeparator(Const Dir : String) : String;
-
- Var
- L : Integer;
-
- begin
- Result:=Dir;
- L:=Length(Result);
- If (L>0) and (Result[l]<>PathSeparator) then
- Result:=Result+PathSeparator;
- end;
-
- Function FileSizeToString(Size: Int64) : String;
-
- Const
- Sizes : Array [0..4] of String =
- ('Bytes','Kb','Mb','Gb','Tb');
- Var
- F : Double;
- I : longint;
-
- begin
- If Size>1024 Then
- begin
- F:=Size;
- I:=0;
- While (F>1024) and (I<4) do
- begin
- F:=F / 1024;
- Inc(i);
- end;
- Result:=Format('%4.2f %s',[F,Sizes[i]]);
- end
- else
- Result:=Format('%d %s',[Size,Sizes[0]]);
- end;
- Function FileAttrsToString(FileAttrs : Integer) : String;
- Const
- Attrs : Array[1..4] of integer =
- (faArchive,faReadOnly,faHidden,faSysfile);
- AttrChars : Array[1..4] of char =
- ('A','R','H','S');
- Var
- i : longint;
- begin
- Result:='';
- For I:=1 to 4 do
- If (Attrs[i] and FileAttrs)=Attrs[i] then
- Result:=Result+AttrChars[i];
- end;
- end.
|