<?php
// First we set up parameters.
$searchpath = JPATH_COMPONENT . '/images';
// Import the folder system library.
jimport('joomla.filesystem.folder');
// Then we create the subfolder called jpg.
if (!JFolder::create($searchpath . "/jpg"))
{
// Throw error message and stop script.
}
// Now we read all jpg files and put them in an array.
$jpgFiles = JFolder::files($searchpath, '.jpg');
// Now we need some stuff from the ''JFile:: class'' to move all the files into the new folder.
foreach ($jpgFiles as $file)
{
JFile::move($searchpath . '/' . $file, $searchpath . '/' . 'jpg' . $file);
}
// Last we move the complete subdir to the root of the component.
if (JFolder::move($searchpath . '/'. 'jpg', JPATH_COMPONENT))
{
// Redirect with perhaps a happy message.
}
else
{
// Throw an error.
}
?>