Contents
English (United Kingdom)French (Fr)Deutsch (DE-CH-AT)
Search
Login
Who Is Online?
We have 33 guests online
Navigation
Home Source Code Inno Setup Scan a disk path or an entire disk with Inno Setup
Most Recent
Featured Articles
Joomla 1.5 Featured Articles
Navigation
Home Source Code Inno Setup Scan a disk path or an entire disk with Inno Setup
English (United Kingdom)French (Fr)Deutsch (DE-CH-AT)
Scan a disk path or an entire disk with Inno Setup E-mail
User Rating: / 10
PoorBest 
Source Code - Inno Setup
Written by Thomas   
Monday, 01 June 2009 19:30
Article Index
Scan a disk path or an entire disk with Inno Setup
Progress page
Cancel button
Example script
All Pages

 

For an installation program I wanted to give the user an option to automatically scan for a particular file on his hard drive or maybe only in a subtree of a drive.

A search through the Inno Setup newsgroups brings up several posts to discourage people to do so. It is understandable, because network and local drives could contain several million files or a similar amount of folders. It could take hours to read the directory tree in and search for a single file. The reasonable alternative is to find the file through other clues like registry entries.

However, the location of the file my installation program is supposed to look for is stored nowhere. The software saves its settings in a Windows ini file, and this file resides just next to the executable file in the same folder.

 

Preparing the Inno Setup script to search for it in a given folder tree or an entire drive seems helpful to the user.

It didn't even look very complicated as the helpfile has a pretty good example on how to use the functions FirndFirst and FindNext. The only minor obstacle was my limited Pascal knowledge which had become a bit rusty over the years, and of course because Inno Setup's Pascal script is not comparable with a fully-featured Pascal compiler.

That's probably the reason why my first attempt didn't want to work on larger directory trees. I kept getting an 'Out of memory' message after a few seconds. I had tried to read the tree into a string array (TArrayOfString) by dynamically expanding it as files and folder names where coming in from the tree reading function. I wanted a flexible function to read the folder tree and then go through the array and process every single file and directory in a second step outside that reading function.

  1. procedure ProcessDirectory (RootDir: String; Progress: Boolean);
  2. var
  3. NewRoot:        String;
  4. FilePath:        String;
  5. FindRec:        TFindRec;
  6. begin
  7. NewRoot := AddBackSlash (RootDir);
  8. if FindFirst (NewRoot + '*', FindRec) then
  9. begin
  10. try
  11. repeat
  12. if (FindRec.Name <> '.') AND (FindRec.Name <> '..') then
  13. begin
  14. FilePath := NewRoot + FindRec.Name;
  15. if FindRec.Attributes AND FILE_ATTRIBUTE_DIRECTORY > 0 then
  16. ReadDirectory (FilePath, Progress)
  17. else
  18. begin
  19. // Start action -->
  20. // .
  21. // Add your custom code here.
  22. // FilePath contains the file name
  23. // including its full path name.
  24. // Try not to call a function for every file
  25. // as this could take a very long time.
  26. // .
  27. // <-- End action.
  28. end;
  29. end;
  30. until NOT FindNext (FindRec);
  31. finally
  32. FindClose(FindRec);
  33. end;
  34. end;
  35. end;
  36.  
  37.  

When this function is called, the installer can't do anything else. In effect, that means that not even the installation wizard's window can be moved. The user interface blocks completely without feeding anything back.

 



Last Updated on Thursday, 15 October 2009 15:26
 
You need to login or register to post comments.
Discuss this item on the forums. (1 posts)
Discuss (1 posts)
Scan a disk path or an entire disk with Inno Setup
Sep 25 2012 06:22:16
This is very helpful post. Thanks for this dude. It really helps me a lot.

*** some spam removed *** (by George)
#1454