<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: glob code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Wed, 23 Jul 2008 17:47:54 GMT</pubDate>
    <description>DZone Snippets: glob code</description>
    <item>
      <title>Image aggregator</title>
      <link>http://snippets.dzone.com/posts/show/4259</link>
      <description>This PHP snippet outputs the contents of a table (beginning &amp; ending tags not included) containing all the images from the current directory.&lt;br /&gt;&lt;code&gt;&lt;?PHP&lt;br /&gt; $columns = 3;&lt;br /&gt; $im = glob("*.{gif,jpg,png}", GLOB_BRACE);&lt;br /&gt; $rows = ceil(count($im) / $columns);&lt;br /&gt; for ($i = 0; $i &lt; $rows; $i++) {&lt;br /&gt;  echo "\n&lt;TR&gt;";&lt;br /&gt;  for ($j = $columns*$i; isset($im[$j]) &amp;&amp; $j - $columns*$i &lt; $columns; $j++) {&lt;br /&gt;   echo "&lt;TD&gt;$im[$j]&lt;BR&gt;&lt;IMG SRC='$im[$j]'&gt;&lt;/TD&gt;";&lt;br /&gt;  }&lt;br /&gt;  echo "&lt;/TR&gt;";&lt;br /&gt; }&lt;br /&gt;?&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 05 Jul 2007 04:08:17 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4259</guid>
      <author>Minimiscience (Guildorn Tanaleth)</author>
    </item>
    <item>
      <title>walk a path</title>
      <link>http://snippets.dzone.com/posts/show/3326</link>
      <description>&lt;code&gt;&lt;br /&gt;#!/usr/bin/env python&lt;br /&gt;&lt;br /&gt;import os&lt;br /&gt;&lt;br /&gt;from os.path import isdir, abspath, join&lt;br /&gt;from glob import iglob&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;def walk(name='.'):&lt;br /&gt;    print abspath(name)&lt;br /&gt;    for item in iglob(join(name, '*')):&lt;br /&gt;        if isdir(item):&lt;br /&gt;            walk(item)&lt;br /&gt;        else:&lt;br /&gt;            print abspath(item)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;if __name__ == '__main__':&lt;br /&gt;    walk()&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 18 Jan 2007 22:20:29 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3326</guid>
      <author>fatalis (Reinis Ivanovs)</author>
    </item>
    <item>
      <title>Create Image Thumbnails (Python)</title>
      <link>http://snippets.dzone.com/posts/show/502</link>
      <description>&lt;code&gt;&lt;br /&gt;# experiments with the Python Image Library (PIL)&lt;br /&gt;&lt;br /&gt;# free from:  http://www.pythonware.com/products/pil/index.htm&lt;br /&gt;&lt;br /&gt;# create 128x128 (max size) thumbnails of all JPEG images in the working folder&lt;br /&gt;&lt;br /&gt;# Python23 tested    vegaseat    25feb2005&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;import glob&lt;br /&gt;import Image&lt;br /&gt;&lt;br /&gt;# get all the jpg files from the current folder&lt;br /&gt;&lt;br /&gt;for infile in glob.glob("*.jpg"):&lt;br /&gt;  im = Image.open(infile)&lt;br /&gt;  # convert to thumbnail image&lt;br /&gt;&lt;br /&gt;  im.thumbnail((128, 128), Image.ANTIALIAS)&lt;br /&gt;  # don't save if thumbnail already exists&lt;br /&gt;&lt;br /&gt;  if infile[0:2] != "T_":&lt;br /&gt;    # prefix thumbnail file with T_&lt;br /&gt;&lt;br /&gt;    im.save("T_" + infile, "JPEG")&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 24 Jul 2005 11:42:24 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/502</guid>
      <author>mattisbusy (Matt Kaufman)</author>
    </item>
    <item>
      <title>php glob_rsort_modtime()</title>
      <link>http://snippets.dzone.com/posts/show/392</link>
      <description>&lt;code&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;/**&lt;br /&gt; FUNCTION: glob_rsort_modtime()&lt;br /&gt; * Glob reverse sorted by file modification time.&lt;br /&gt; *&lt;br /&gt; * Returns an array of files matching the given glob pattern, sorted &lt;br /&gt; * by their modification times in descending order.  The array keys&lt;br /&gt; * hold the filepath and the values hold the mtime.  On error, array&lt;br /&gt; * will be indexed and contain 'false' and an error message.&lt;br /&gt; *&lt;br /&gt; * {@source}&lt;br /&gt; *&lt;br /&gt; * @param string $patt Pattern to search, including glob braces.&lt;br /&gt; * @return array filename =&gt; mtime OR false, 'errormsg'.&lt;br /&gt; */&lt;br /&gt;function glob_rsort_modtime( $patt ) {&lt;br /&gt;    if ( ( $files = @glob($patt, GLOB_BRACE) ) === false ) {&lt;br /&gt;        return array( false, 'Glob error.');&lt;br /&gt;    }&lt;br /&gt;    if ( !count($files) ) {&lt;br /&gt;        return array( false, 'No files found.');&lt;br /&gt;    }&lt;br /&gt;    $rtn = array();&lt;br /&gt;    foreach ( $files as $filename ) {&lt;br /&gt;        $rtn[$filename] = filemtime($filename);&lt;br /&gt;    }&lt;br /&gt;    arsort($rtn);&lt;br /&gt;    reset($rtn);&lt;br /&gt;    return $rtn;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;$files = glob_rsort_modtime( './*' ) ;&lt;br /&gt;echo'&lt;pre&gt;'.print_r($files, true).'&lt;/pre&gt;';&lt;br /&gt;?&gt; &lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 17 Jun 2005 14:01:29 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/392</guid>
      <author>danostuporstar (Dano Stuporstar)</author>
    </item>
  </channel>
</rss>
