|
Page 1 of 1 |
|
Posted: Sat, 21st Jun 2014 16:08 Post subject: Writing a batch file |
|
 |
I need a batch file that will pull the images from a folder with like 1300 images, and put it in a file that will look like this
Code: | <?xml version="1.0" encoding="ISO-8859-1"?>
<settings>
<slideshow>
<page>
<photo image="images/gazo_a0000.jpg"></photo>
</page>
<page>
<photo image="images/gazo_a0001.jpg"></photo>
<photo image="images/gazo_a0002.jpg"></photo>
</page>
<page>
<photo image="images/gazo_a0003.jpg"></photo>
<photo image="images/gazo_a0004.jpg"></photo>
</page>
<page>
<photo image="images/gazo_a0005.jpg"></photo>
<photo image="images/gazo_a0006.jpg"></photo>
</page>
<page>
<photo image="images/gazo_a0007.jpg"></photo>
<photo image="images/gazo_a0008.jpg"></photo>
</page>
<lastpage>
<photo image="images/gazo_c0046.jpg"></photo>
</lastpage>
</slideshow>
</settings> |
I need it to group two images inside a <page> tag like the above. Is that possible, or should I look for a better solution?
"Quantum mechanics is actually, contrary to it's reputation, unbeliveably simple, once you take the physics out."
Scott Aaronson chiv wrote: | thats true you know. newton didnt discover gravity. the apple told him about it, and then he killed it. the core was never found. |
|
|
Back to top |
|
 |
Werelds
Special Little Man
Posts: 15098
Location: 0100111001001100
|
Posted: Sat, 21st Jun 2014 16:12 Post subject: |
|
 |
That's better suited to do in a scripting language, doing that in a batch file (or even a bash script) will be quite annoying.
I take it you're on Windows?
Got PHP installed?
|
|
Back to top |
|
 |
|
Posted: Sat, 21st Jun 2014 16:14 Post subject: |
|
 |
Werelds wrote: | That's better suited to do in a scripting language, doing that in a batch file (or even a bash script) will be quite annoying.
I take it you're on Windows?
Got PHP installed? |
This is actually for a web site, a stupid page flip module I'm using. Apparently they haven't figured out how to pull all the pictures from a folder, so you need to do it manually -.-"
"Quantum mechanics is actually, contrary to it's reputation, unbeliveably simple, once you take the physics out."
Scott Aaronson chiv wrote: | thats true you know. newton didnt discover gravity. the apple told him about it, and then he killed it. the core was never found. |
|
|
Back to top |
|
 |
Werelds
Special Little Man
Posts: 15098
Location: 0100111001001100
|
Posted: Sat, 21st Jun 2014 16:17 Post subject: |
|
 |
Gimme a few minutes to whip something up for you 
|
|
Back to top |
|
 |
|
Posted: Sat, 21st Jun 2014 16:19 Post subject: |
|
 |
Thanks
"Quantum mechanics is actually, contrary to it's reputation, unbeliveably simple, once you take the physics out."
Scott Aaronson chiv wrote: | thats true you know. newton didnt discover gravity. the apple told him about it, and then he killed it. the core was never found. |
|
|
Back to top |
|
 |
Werelds
Special Little Man
Posts: 15098
Location: 0100111001001100
|
Posted: Sat, 21st Jun 2014 16:40 Post subject: |
|
 |
Code: | <?php
/*
* Configuration
*/
/** @var string $dir Path to the images */
$dir = 'images';
/** @var string[] $extensions Extensions to include */
$extensions = array('jpg', 'png', 'gif');
/** @var int $per_page Number of images per page */
$per_page = 2;
/** @var bool $debug If set to true, will show errors */
$debug = false;
/*
* Shit starts happening here
*/
// Unless we're debugging, ignore all errors
error_reporting($debug ? E_ALL : 0);
// Trim any trailing slashes just to be sure
$dir = rtrim(trim($dir), '/');
// Clean up the extensions
$extensions = array_map('trim', $extensions);
// Build the file pattern
$pattern = sprintf('%s/*.{%s}', $dir, implode(',', $extensions));
// Create the base element
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8" ?><settings></settings>');
// Create the slideshow element
$slideshow = $xml->addChild('slideshow');
// Create the first page
$page = $slideshow->addChild('page');
// Iterate over the files
$files = glob($pattern, GLOB_BRACE);
foreach ($files as $index => $file) {
// If index is a multiple of $per_page, we need a new page - goes for index 0 too
if ($index > 0 && $index % $per_page === 0) {
// And if we're within $per_page of the total number of files, we need a lastpage element instead
$page_type = ($index >= (count($files) - $per_page)) ? 'lastpage' : 'page';
$page = $slideshow->addChild($page_type);
}
$photo = $page->addChild('photo');
$photo->addAttribute('image', $file);
}
header('Content-type: text/xml');
echo $xml->asXML(); |
Just drop it somewhere, fill in the path at the top and you're set.
As presented above it will produce your exact output if you drop it one level up from the images
So if you've got the site running at c:\sites\this and the images are in c:\sites\this\images - drop it in c:\sites\this and visit it at domain.dev/whateveryoucalledthefile.php
|
|
Back to top |
|
 |
|
Posted: Sat, 21st Jun 2014 17:56 Post subject: |
|
 |
Thank you ^^
Works like a charm! You rock 
"Quantum mechanics is actually, contrary to it's reputation, unbeliveably simple, once you take the physics out."
Scott Aaronson chiv wrote: | thats true you know. newton didnt discover gravity. the apple told him about it, and then he killed it. the core was never found. |
|
|
Back to top |
|
 |
Werelds
Special Little Man
Posts: 15098
Location: 0100111001001100
|
Posted: Sat, 21st Jun 2014 19:01 Post subject: |
|
 |
|
|
Back to top |
|
 |
Page 1 of 1 |
All times are GMT + 1 Hour |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB 2.0.8 © 2001, 2002 phpBB Group
|
|
 |
|