summaryrefslogtreecommitdiff
path: root/src/corelib/fpg_utils.pas
diff options
context:
space:
mode:
authorgraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2009-01-12 15:08:53 +0000
committergraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2009-01-12 15:08:53 +0000
commit1991b86c925074dd7f2d7dd93f5fbd0c4aabcc0e (patch)
tree3d62c79db749bf5aea8de11590bf3966c643b2e7 /src/corelib/fpg_utils.pas
parent05a2481075f5ffdccc094647563d341745add986 (diff)
downloadfpGUI-1991b86c925074dd7f2d7dd93f5fbd0c4aabcc0e.tar.xz
* Added two new functions to fpg_utils unit.
* More work on the Select Directory dialog.
Diffstat (limited to 'src/corelib/fpg_utils.pas')
-rw-r--r--src/corelib/fpg_utils.pas49
1 files changed, 48 insertions, 1 deletions
diff --git a/src/corelib/fpg_utils.pas b/src/corelib/fpg_utils.pas
index 2edd1eab..7d5871c9 100644
--- a/src/corelib/fpg_utils.pas
+++ b/src/corelib/fpg_utils.pas
@@ -45,7 +45,8 @@ function fpgGetCurrentDir: TfpgString;
function fpgSetCurrentDir(const NewDir: TfpgString): Boolean;
function fpgExpandFileName(const FileName: TfpgString): TfpgString;
function fpgFileExists(const FileName: TfpgString): Boolean;
-
+function fpgAppendPathDelim(const Path: TfpgString): TfpgString;
+function fpgHasSubDirs(const Dir: TfpgString; AShowHidden: Boolean): Boolean;
implementation
@@ -111,6 +112,52 @@ begin
Result := FileExists(fpgToOSEncoding(FileName));
end;
+function fpgAppendPathDelim(const Path: TfpgString): TfpgString;
+begin
+ if (Path <> '') and (Path[length(Path)] <> PathDelim) then
+ Result := Path + PathDelim
+ else
+ Result := Path;
+end;
+
+{function fpgHasSubDirs returns True if the directory passed has subdirectories}
+function fpgHasSubDirs(const Dir: TfpgString; AShowHidden: Boolean): Boolean;
+var
+ FileInfo: TSearchRec;
+ FCurrentDir: TfpgString;
+begin
+ //Assume No
+ Result := False;
+ if Dir <> '' then
+ begin
+ FCurrentDir := fpgAppendPathDelim(Dir);
+ FCurrentDir := FCurrentDir + AllFilesMask;
+ try
+ if fpgFindFirst(FCurrentDir, faAnyFile or $00000080, FileInfo) = 0 then
+ repeat
+ if FileInfo.Name = '' then
+ Continue;
+
+ // check if special file
+ if ((FileInfo.Name = '.') or (FileInfo.Name = '..')) or
+ // unix dot directories (aka hidden directories)
+ ((FileInfo.Name[1] in ['.']) and AShowHidden) or
+ // check Hidden attribute
+ (((faHidden and FileInfo.Attr) > 0) and AShowHidden) then
+ Continue;
+
+ Result := ((faDirectory and FileInfo.Attr) > 0);
+
+ //We found at least one non special dir, that's all we need.
+ if Result then
+ break;
+ until fpgFindNext(FileInfo) <> 0;
+ finally
+ FindClose(FileInfo);
+ end;
+ end;
+end;
+
end.