Paradox Community
Search:

 Welcome |  What is Paradox |  Paradox Folk |  Paradox Solutions |
 Interactive Paradox |  Paradox Programming |  Internet/Intranet Development |
 Support Options |  Classified Ads |  Wish List |  Submissions 


Paradox Programming Articles  |  Beyond Help Articles  |  Tips & Tricks Articles  


Finding files on your computer and sorting an array
© 2001, Arthur van Lokhorst

My homepage, which is all Dutch and has nothing to do with Paradox, except that almost every single page was written to a html-text file with Paradox


Synopsis:
This page refers to frmFileFind.fsl, which can be downloaded as a zipped archive. What the form demonstrates is:
  • finding a file anywhere on your computer
  • some sorting routines
  • listing all drives on your computer (A:\, B:\, C:\ etc)
  • listing all hard drives on your computer (C:\, D:\ etc.)
  • getting the Temp-folder by calling the Windows API
  • listing the entire source code of a form to a file in your temp folder

Recursion:

Recursion is a repeated call on a function by that same function. To get an idea of what is happening imagine yourself at your desk. Every time the phone rings you make a note of what you were doing, and you then put the callers file on top of a heap of files on your desk, with a note of what to do with that call. During the day you work your way down the heap, adding files when the phone rings, and working down the heap when the phone does not ring, but always starting on the last file added. At the end of day, you want to have a clear desk.


Finding files:

A recursive file find works almost the same. Every time the function calls itself, Windows takes note of the current state of the function, processes the recursive call, and returns to the function to finish what is left undone.

The form frmFileFind.fsl demonstrates a recursive file find, in two varieties. Both can search for a file that matches a file name (case insensitive), while wild cards are allowed. Set the search pattern as you would do when searching from Windows.

The first variety calls a method (called cpFindFile) to find every matching file. The second variety calls a method (called cpFindFileLimited) that stops processing as soon as a file is found that matches your search pattern. If you are only looking for one particular file, the second variety is faster. But please note that this second variety can come up with multiple results, as running the form will demonstrate. The number of return values depends on (but is not equal to) the number of recursive calls before a match is found.

The speed of finding files is inhibited by the fact that search results are written to a list box. If you are searching for only one file, the effect is negligible. If you are searching for all files, the slowdown is considerable. In that case, you might want to return an array from the file find method. Writing to a list box further implies that you can not list more items than a list box can hold (which equals the limits of a small integer, so somewhat in excess of 32,000).


Sorting an array:

A lazy way of sorting is to write the results of an operation to a sorted list box. The snag with that trick is, that a sorted list box normally is not able to hold duplicate values. Perhaps you want to eliminate duplicates, or perhaps duplicate entries can not be imagined (as with file names, because the full name is always unique). The preferred way of sorting however is to code it. So I have added the possibility to sort the list box, to demonstrate how to sort an array using a shell sort and a quick sort. To my knowledge these are the two most popular sorting algorithms.

Shell sort:
The shell sort does not use recursion, so it can be used in any programming language that does not support it (I am not sure whether PerfectScript supports recursion). In addition, it lends itself to show a progress bar (users always want to see that something is happening, even if it slows processing down).

Quick sort:
The quick sort uses recursion. Normally, the quick sort is the fastest routine of the two. The time to do a quick sort depends on both the size of the array and on whether it is more or less sorted already.

Sorting to a table:
The time needed to do a shell sort or a quick sort increases dramatically with the number of elements in the array. I use as cut_off a number of 1,000 elements. If the array is larger, I use a table to sort on. Using a table, my computer sorts an array with 25,000 elements in 7 seconds. A table, however, is less flexible. You have to adjust the code to the variable type in the array. The shell sort and the quick sort can sort both arrays with numbers and arrays with strings.


Buttons on the form:

The form is designed in such a way that you can cut and paste every command button to another form, with full functionality. But the button list source will only list the source code of the form properly to a file in your temp-folder if the title of the form you are working on would be a valid file name under Windows. All other buttons contain code that refers to an object on the form, which you may have to adjust.


Code:

If you have any suggestions about the code please send me mail at a.van.lokhorst@hccnet.nl

Arthur van Lokhorst, Rotterdam
25 August 2001


Discussion of this article


 Feedback |  Paradox Day |  Who Uses Paradox |  I Use Paradox |  Downloads 


 The information provided on this Web site is not in any way sponsored or endorsed by Corel Corporation.
 Paradox is a registered trademark of Corel Corporation.


 Modified: 15 May 2003
 Terms of Use / Legal Disclaimer


 Copyright © 2001- 2003 Paradox Community. All rights reserved. 
 Company and product names are trademarks or registered trademarks of their respective companies. 
 Authors hold the copyrights to their own works. Please contact the author of any article for details.