cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
bwlf
Level 3

FindAllFiles is not returning files in sub directorys

Dear,

I have a problem with an InstallShield script function: FindAllFiles.
This is not returning the files in the sub folders.
This is my script:

function GetFileListExt( svSourceDir, szFileMask, lList, bFileExt )

STRING svFile; // The file found in the SourceDir
BOOL bFileFound;

begin
bFileFound = TRUE;

// Search the SourceDir for the given file mask
bFileFound = FindAllFiles( svSourceDir, szFileMask, svFile, RESET );
while( bFileFound = 0)

// Leave only the filename
if bFileExt = 1 then
ParsePath( svFile, svFile, FILENAME);
else
ParsePath( svFile, svFile, FILENAME_ONLY);
endif;
ListAddString( lList, svFile, AFTER );

// Search the SourceDir for the given file mask
bFileFound = FindAllFiles( svSourceDir, szFileMask, svFile, CONTINUE );
endwhile;

// Free access to files and folders
FindAllFiles( svSourceDir, szFileMask, svFile, CANCEL );
end;

Remark :
svSourceDir = SUPPORTDIR = C:\DOCUME~1\BWLF~1.GUL\LOCALS~1\Temp\1\{3FA03AE9-72C3-45BE-A711-39AA8973C4F1}\{47B8FA93-AF58-41BA-92A5-6F3C55BA34E3}\ImportOnce

<--- does contain sub directorys and files

What am i doing wrong here ?
Please help.
Regards,
Bernard
Labels (1)
0 Kudos
(4) Replies
bwlf
Level 3

Strangely enough when I delete the files in the main folder and leave only files in the sub folder the the function FindAllFiles is finding the files in the subs...
0 Kudos
rrinblue22
Level 9

Check this if it works for you.
it was probably from Installsite.org but it works at my end.

//////////////

#include "ifx.h"

function OnBegin()



STRING szMsg, svDir, svFileSpec, svMatchingFileName, svNumFiles;

NUMBER nResult, nNumFiles;

LIST listFiles;

begin


selectdir:


// Set up parameters for call to SelectDir.

szMsg = "Select a directory to search.";

svDir = "";


// Select a search directory.

SelectDir ("", szMsg, svDir, FALSE);


askfile:

szMsg = "Enter a file specification to search for in " + svDir + ":";


// Get a file specification from the user.

if (AskText (szMsg , "*.*", svFileSpec) = BACK) then

goto selectdir;

endif;


// Create a string list for the file listing.

listFiles = ListCreate (STRINGLIST);


if listFiles = LIST_NULL then

MessageBox ("Unable to create list.", SEVERE);

abort;

endif;


// Set the file count to zero.

nNumFiles = 0;


// Show a message while the file list is being built.

SdShowMsg ("Searching . . . ", TRUE);


// Get the first file that matches the file spec.

nResult = FindAllFiles (svDir, svFileSpec, svMatchingFileName, RESET);


while(nResult = 0)

// Add the file to the list.

if ListAddString (listFiles, svMatchingFileName, AFTER) < 0 then

MessageBox ("Unable to build complete file list", WARNING);

goto showmatches;

endif;


// Increment the file counter.

nNumFiles = nNumFiles + 1;


// Find the next matching file name.

nResult = FindAllFiles(svDir, svFileSpec, svMatchingFileName, CONTINUE);

endwhile;


showmatches:


// Free all files and folders accessed by FindAllFiles. If your

// setup does not target the Windows NT platform, this step is

// not necessary.

FindAllFiles(svDir, svFileSpec, svMatchingFileName, CANCEL);


// Convert the file count to a string for display.

NumToStr(svNumFiles, nNumFiles);


// Clear the message that displayed while the file list was being built.

SdShowMsg("", FALSE);


// Display the files that match the file specification.

szMsg = "Number of matching files : " + svNumFiles;

if (SdShowInfoList("", szMsg, listFiles) = BACK) then

ListDestroy(listFiles);

goto askfile;

endif;


// Remove the list from memory.

ListDestroy(listFiles);


end;
//////////////
0 Kudos
bwlf
Level 3

Hy rrinblue22,

With the help of your function I found the problem.
Apparently the list to put the files in should be created within the function, if not the FindAllFiles does not return matches in sub folders. Odd although.
Thanx for your help, I appreciate it.

Regards,
Bernard
0 Kudos
bwlf
Level 3

Hi,

The problem re-occurs again !
I am now solving it with a call to FindAllDirs, this seems to work consistently

Regards,
Bernard


prototype LIST GetaList( STRING, STRING, BOOL);

//-----------------------------------------------------------------------
function LIST GetaList( svSourceDir, szFileMask, bSearchSubs)

NUMBER nOk, nSubOk, nOkSubFile;
STRING svFile, svStorePath, svTheFile, sMsg, svSub;
LIST lFullPath, lSubs;

begin

// Create an empty number list.
lFullPath = ListCreate (STRINGLIST);

// If an error occurred, report it; then terminate.
if (lFullPath = LIST_NULL) then
MessageBox ("Unable to create list.", SEVERE);
abort;
endif;

// Create an empty number list.
lSubs = ListCreate (STRINGLIST);

// If an error occurred, report it; then terminate.
if (lSubs = LIST_NULL) then
MessageBox ("Unable to create list.", SEVERE);
abort;
endif;

// Search the SourceDir for the given file mask
nOk = FindAllFiles( svSourceDir, szFileMask, svFile, RESET );

while( nOk = 0 )
ListAddString( lFullPath, svFile, AFTER);
nOk = FindAllFiles( svSourceDir, szFileMask, svFile, CONTINUE );
endwhile;

if bSearchSubs = TRUE then
FindAllDirs( svSourceDir, INCLUDE_SUBDIR ,lSubs);
if ListCount(lSubs) > 0 then
nSubOk = ListGetFirstString(lSubs,svSub);
while (nSubOk = 0)
nOkSubFile = FindAllFiles( svSub, szFileMask, svFile,RESET );
while (nOkSubFile = 0)
ListAddString( lFullPath, svFile, AFTER);
nOkSubFile = FindAllFiles( svSub, szFileMask, svFile, CONTINUE );
endwhile;
FindAllFiles( svSub, szFileMask, svFile, CANCEL );
nSubOk = ListGetNextString(lSubs,svSub);
endwhile;
endif;
endif;
FindAllFiles( svSourceDir, szFileMask, svFile, CANCEL );

NumToStr( sMsg, ListCount(lFullPath));
MessageBox("Number of files found = " + sMsg,INFORMATION);
SdShowInfoList("All found files","Files",lFile);
ListDestroy(lSubs);
return lFullPath;

end;
0 Kudos