/**
 *        __       __               __ 
 *   ____/ /_ ____/ /______ _ ___  / /_
 *  / __  / / ___/ __/ ___/ / __ `/ __/
 * / /_/ / (__  ) / / /  / / /_/ / / 
 * \__,_/_/____/_/ /_/  /_/\__, /_/ 
 *                           / / 
 *                           \/ 
 * https://distriqt.com
 *
 * @brief  		
 * @author 		marchbold
 * @created		11/4/18
 * @copyright	https://distriqt.com/copyright/license.txt
 */
package com.distriqt.utils
{
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	import flash.filesystem.FileStream;
	import flash.utils.ByteArray;
	
	
	public class FileUtils
    {
 		////////////////////////////////////////////////////////
        //  CONSTANTS
        //
        
        private static const TAG : String = "FileUtils";
        
        
 		////////////////////////////////////////////////////////
        //  VARIABLES
        //
        

 		////////////////////////////////////////////////////////
        //  FUNCTIONALITY
        //
        
        public function FileUtils() 
        {
        }
	
	
		public static function copyTo( sourceDir:File, destDir:File ):void
		{
//			sourceDir.copyTo( destDir );
		
			var bytes:ByteArray = new ByteArray();
			var stream:FileStream = new FileStream();
			var iterate:Function = function ( dir:File, path:String ):void
			{
				var files:Array = dir.getDirectoryListing();
				for each (var file:File in files)
				{
					if (file.isDirectory)
					{
						iterate( file, path + file.name + File.separator );
					}
					else
					{
						bytes.clear();
						stream.open( file, FileMode.READ );
						stream.readBytes( bytes );
						stream.close();
						var dest:File = destDir.resolvePath( path + file.name );
						stream.open( dest, FileMode.WRITE );
						stream.writeBytes( bytes );
						stream.close();
					}
				}
			}
			iterate( sourceDir, "" );
		
		}
	
	
	
	}
}
