Is there anyway to get all (or just the first) subfolder in a directory? I'm trying to install my files into a subdirectory that has a dynamic name. It is not one of the constants available with Inno Setup. Is there anyway to find this subdirectory name?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Well, to get name of a first found subfolder of a certain folder, no matter which one it is, you may use the following function:
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
[Code]
function TryGetFirstSubfolder(const Path: string; out Folder: string): Boolean;
var
S: string;
FindRec: TFindRec;
begin
Result := False;
if FindFirst(ExpandConstant(AddBackslash(Path) + '*'), FindRec) then
try
repeat
if (FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY <> 0) and
(FindRec.Name <> '.') and (FindRec.Name <> '..') then
begin
Result := True;
Folder := AddBackslash(Path) + FindRec.Name;
Exit;
end;
until
not FindNext(FindRec);
finally
FindClose(FindRec);
end;
end;
procedure InitializeWizard;
var
S: string;
begin
if TryGetFirstSubfolder('C:\Folder', S) then
MsgBox('The first found subfolder is: ' + S, mbInformation, MB_OK);
end;