# ? geting the number of jpg's as a variable from a folder

**URL:** <https://forum.kirupa.com/t/geting-the-number-of-jpgs-as-a-variable-from-a-folder/57399>\
**Category:** Uncategorized\
**Created:** [July 12, 2004, 11:15pm UTC](https://forum.kirupa.com/t/geting-the-number-of-jpgs-as-a-variable-from-a-folder/57399 "2004-07-12T23:15:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![beenetto](https://avatars.discourse-cdn.com/v4/letter/b/c2a13f/32.png) [@beenetto](https://forum.kirupa.com/u/beenetto)\
**Post date:** [July 12, 2004, 11:15pm UTC](https://forum.kirupa.com/t/geting-the-number-of-jpgs-as-a-variable-from-a-folder/57399/1 "2004-07-12T23:15:11Z")

</div>

hello,

how can i give a value to my variable depending on how many .jpg’s i have  
in my pictures folder.  
lets say I have 53 jpg’s in the pictures folder and I need myvariable=53,  
and if i put the 54th in, flash should update this value on \_root.onLoad or on  
what ever.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 12, 2004, 11:52pm UTC](https://forum.kirupa.com/t/geting-the-number-of-jpgs-as-a-variable-from-a-folder/57399/2 "2004-07-12T23:52:15Z")

</div>

I don’t believe flash can do this alone, I normally use a php script to list directory contents:

```auto

 <?
  	// Open directory
  	$myDirectory = opendir("path	o\directory");
  	// get each entry
  	while($entryName = readdir($myDirectory))
  	{
  	$dirArray[] = $entryName;
  	}
  	// close directory
  	closedir($myDirectory);
  	// count elements in array
  	$indexCount	= (count($dirArray));
  	// return the amount of files in the directory to flash with :
      print "&myVariable=" . urlencode($indexCount+1);
 ?>
  

```

Save that as listdirectory.php and use the following code in flash:

```auto

  dirCount = new LoadVars();
  dirCount.load("http://path_to/listdirectory.php");
  dirCount.onLoad = function(success) {
  	if (success) {
  		_root.myVariable = this.myVariable;
  	} else {
  		trace("directory listing error");
  	}
  

```

Then just call the function everytime you want to flash to check/update/refresh the variable, by using this:

```auto
 
  dirCount();
  

```

Hope this helps… off the top of my head, but it should work okay.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 13, 2004, 12:20am UTC](https://forum.kirupa.com/t/geting-the-number-of-jpgs-as-a-variable-from-a-folder/57399/3 "2004-07-13T00:20:34Z")

</div>

thanks,  
It works perfect.
