Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Capturing File Count
Message
From
29/08/2017 02:58:20
 
 
To
28/08/2017 22:56:20
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 7 SP1
OS:
Windows 10
Miscellaneous
Thread ID:
01653809
Message ID:
01653819
Views:
69
>>>Howdy experts,
>>>
>>>I am looking to calculate the number of files. I have a folder called bkngimgs. I want to allow my setup program to Capture the number of images that are in that irectory and then use that number to get a random number and select that file for the background image for my intial splash screen.
>>>
>>>Any ideas how to accomplish this? Is this a good approach or should I look at capturing all file names into a table and generating the random record against the table?
>>
>>A concise way to do it:
>>
>>
>>* set to match your image repository and extension
>>#DEFINE IMAGES_REPOSITORY	"C:\Users\" + ALLTRIM(SUBSTR(SYS(0), AT("#", SYS(0)) + 1)) + "\Pictures\*.jpg"
>>
>>LOCAL ARRAY Images(1)
>>
>>? m.Images(EVL(ROUND(RAND() * ADIR(m.Images, IMAGES_REPOSITORY), 0), 1), 1)
>>
>
>Hrm... I don't recall if VFP7 had limit to the array size as did older versions such as VFP 6.0 (65,000 elements). In the unlikely situation where there are more than 13,000 files ADIR() will error out (ADIR() returns two-dimensional array with 5 columns -- maximum size would them mean 65000/5 = 13000 rows). In such cases, SYS(2000) could be used to iterate through list
>[pre]cPattern = "bkngimgs\*.*"
>nCnt = 0
>cRet = SYS(2000,m.cPattern) && Get first match
>DO WHILE NOT EMPTY(m.cRet)
> nCnt = m.nCnt + 1
> ? m.nCnt, m.cRet
> cRet = SYS(2000,"",1) && Get next match
>ENDDO
>[/pre]
>
> -- but it might be faster to "shell out" to command line and use DIR command and redirect its output to text file (you can use /B option to get only filenames), then pull in the contents of the table using APPEND FROM.

If the number of images in the repository goes into the thousands, I wouldn't advise to use any method based on a directory scanning (not for Jeffrey's purpose, that is, to pick an image for a splash screen).

But you raise a point that I disregarded: it's for VFP7, and I think that the EVL() function appeared only in VFP8. It must be recreated in the same (at least, close) way.
FUNCTION EVL
LPARAMETERS SomeValue, OnEmptyValue

IF EMPTY(m.SomeValue)
  RETURN m.OnEmptyValue
ELSE
  RETURN m.SomeValue
ENDIF

ENDFUNC
----------------------------------
António Tavares Lopes
Previous
Reply
Map
View

Click here to load this message in the networking platform