# PNG Conversion script looks in folder - need to look in subfolders

**URL:** <https://forum.kirupa.com/t/png-conversion-script-looks-in-folder-need-to-look-in-subfolders/634167>\
**Category:** flash\
**Created:** [January 21, 2016, 12:43am UTC](https://forum.kirupa.com/t/png-conversion-script-looks-in-folder-need-to-look-in-subfolders/634167 "2016-01-21T00:43:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![NewYears1978](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/newyears1978/32/7455_2.png) [@NewYears1978](https://forum.kirupa.com/u/NewYears1978)\
**Post date:** [January 21, 2016, 12:43am UTC](https://forum.kirupa.com/t/png-conversion-script-looks-in-folder-need-to-look-in-subfolders/634167/1 "2016-01-21T00:43:30Z")

</div>

I have a script as follows:

```auto
/*
* PNG2SWF_MULTIPLE JSFL v 1.0
* by Matus Laco, http://www.YoFLA.com
* Modified by dark13 to embedd PNGs as uncompressed files and allow smoothing
* product URL: http://www.yofla.com/flash/png2swf/
* inspired by Mr.doob http://mrdoob.com/tools/jsfl/png2swf.jsfl
*
* Description:
* Converts multiple png files to multiple swf files.
* Input: Select folder dialog box
* Output: Same folder, same filename, swf extension
*/

png2swf();

function png2swf()
{
	var folderURI = fl.browseForFolderURL("Select a folder.");
	if (folderURI == null) { return; }
	var folderContents = FLfile.listFolder(folderURI);

	var doc = fl.createDocument();
	doc.backgroundColor = '#00FF00';
	
	var imported = 0;
		
	for(var i=0; i< folderContents.length; i++){
		
					
		var pngURI = folderURI + "/" +folderContents[i];
		if (pngURI.substr(pngURI.length-4) != ".png") continue;
		
		doc.importFile(pngURI);
		
		// get item		
		var bmp_lib = doc.library.items[imported];
		bmp_lib.compressionType = "lossless";		
                bmp_lib.allowSmoothing = true;
		var bmp_tl = fl.getDocumentDOM().getTimeline().layers[0].frames[0].elements[0];
                 
// Scale from 1080p to 1024*768 and apply 16:9 ratio correction
                bmp_tl.scaleX = 0.53333 ;
                bmp_tl.scaleY = 0.7111 ;
                bmp_tl.x = 0 ;
    	        bmp_tl.y = 0 ;

// set doc size
		doc.width = Math.floor(bmp_tl.width)+1;
		doc.height = Math.floor(bmp_tl.height)+1;	
// export	
		var swfURI = pngURI.substr(0,pngURI.lastIndexOf(".")+1)+"swf";
		doc.exportSWF(swfURI, true );
		
		// remove previous from timeline
		doc.selectAll();
		doc.deleteSelection();
		
		// increase imported count
		imported++;
	}
	
	doc.close(false);
	
	alert(imported + " files created.");
}
```

Which looks in a folder you select and then converts PNG into SWF files. I need the script to also look in subfolders of the selected folder.

Thanks in advance for any help.
