[ ik0 @ 01.10.2010. 09:47 ] @
ove funkcije napisane u delphiju nemogu nikako da napisem u c++...evo kodo a pod njega i mog koda (ono sto sam uspeo da napisem) Code: function GetParentDirectory(path : string) : string; begin result := ExpandFileName(path + '..') end; function AddFilter(path,filter: string): string; begin if length(path) > 0 then begin if path[length(path)] = '' then result := path + filter else result := path + '' + filter; end else result := filter; end; type TFileInfo = record Icon : hIcon; Image : Integer; DisplayName : String; TypeName : String; Size : Integer; SizeDescription : String; DateTime : TDateTime; AttrArchive : Boolean; AttrReadOnly : Boolean; AttrSystem : Boolean; AttrHidden : Boolean; AttrVolume : Boolean; AttrDirectory : Boolean; end; // ---------------------------------------------------------------- // Return string with formatted file size (bytes, Kb, Mb or Gb) // ---------------------------------------------------------------- function scGetSizeDescription(const IntSize : Int64) : String; begin if IntSize < 1024 then Result := IntToStr(IntSize)+' bytes' else begin if IntSize < (1024 * 1024) then Result := FormatFloat('####0.##',IntSize / 1024)+' Kb' else if IntSize < (1024 * 1024 * 1024) then Result := FormatFloat('####0.##',IntSize / 1024 / 1024)+' Mb' else Result := FormatFloat('####0.##',IntSize / 1024 / 1024 / 1024)+' Gb'; end; end; // ---------------------------------------------------------------- // Return record with all information about given file // How to use icon : ImageFile.Picture.Icon.Handle:=Info.Icon; // ---------------------------------------------------------------- procedure scGetFileInfo(StrPath : String; var Info : TFileInfo); var SHFileInfo : TSHFileInfo; SearchRec : TSearchRec; begin if Trim(StrPath) = '' then Exit; ShGetFileInfo(PChar(StrPath), 0, SHFileInfo, SizeOf (TSHFileInfo), SHGFI_TYPENAME or SHGFI_DISPLAYNAME or SHGFI_SYSICONINDEX or SHGFI_LARGEICON or SHGFI_ICON); with Info do begin Icon := SHFileInfo.hIcon; Image := SHFileInfo.iIcon; DisplayName := SHFileInfo.szDisplayName; TypeName := SHFileInfo.szTypeName; end; FindFirst(StrPath, 0, SearchRec); with Info do begin try DateTime := FileDateToDateTime(SearchRec.Time); except DateTime := Now(); end; {$WARNINGS OFF} AttrReadOnly := ((SearchRec.Attr and faReadOnly) > 0); AttrSystem := ((SearchRec.Attr and faSysFile) > 0); AttrHidden := ((SearchRec.Attr and faHidden) > 0); AttrArchive := ((SearchRec.Attr and faArchive) > 0); AttrVolume := ((SearchRec.Attr and faVolumeID) > 0); AttrDirectory := ((SearchRec.Attr and faDirectory) > 0); {$WARNINGS ON} Size := SearchRec.Size; SizeDescription := scGetSizeDescription(Size); end; end; |