{"id":5573,"date":"2013-01-14T07:00:00","date_gmt":"2013-01-14T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2013\/01\/14\/how-can-i-write-a-script-that-finds-my-top-rated-photos\/"},"modified":"2013-01-14T07:00:00","modified_gmt":"2013-01-14T07:00:00","slug":"how-can-i-write-a-script-that-finds-my-top-rated-photos","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20130114-00\/?p=5573\/","title":{"rendered":"How can I write a script that finds my top-rated photos?"},"content":{"rendered":"<p><P>\nI&#8217;m not sure if I&#8217;ll be able to keep it up,\nbut I&#8217;m going to see if I can make Monday\n&#8220;Little Programs&#8221; day,\nwhere I solve simple problems with little programs.\n<\/P>\n<P>\nToday&#8217;s little program is a script that\ngoes through your Pictures folder and picks out your top-rated photos.\n<\/P>\n<P>\nThe key step here is extracting the rating,\nwhich goes by the name\n<A HREF=\"http:\/\/msdn.microsoft.com\/library\/windows\/desktop\/bb787554.aspx\">\n<CODE>System.Rating<\/CODE><\/A>\nin the shell property system.\nThe method which does the extraction is\n<A HREF=\"http:\/\/msdn.microsoft.com\/library\/windows\/desktop\/bb774055.aspx\">\n<CODE>Shell&shy;Folder&shy;Item.Extended&shy;Property<\/CODE><\/A>.\n<\/P>\n<PRE>\nvar shell = new ActiveXObject(&#8220;<A HREF=\"http:\/\/msdn.microsoft.com\/library\/bb776890.aspx\">Shell.Application<\/A>&#8220;);\nvar picturesFolder = shell.Namespace(39); \/\/ CSIDL_MYPICTURES\nvar items = picturesFolder.Items();\nvar SHCONTF_NONFOLDERS = 64;\nitems.<A HREF=\"http:\/\/msdn.microsoft.com\/library\/bb787787.aspx\">Filter<\/A>(SHCONTF_NONFOLDERS, &#8220;*.jpg&#8221;);\nfor (var i = 0; i &lt; items.Count; i++) {\n  var item = items.Item(i);\n  if (item.ExtendedProperty(&#8220;System.Rating&#8221;) &gt;= 80) {\n    WScript.StdOut.WriteLine(item.Path);\n  }\n}\n<\/PRE>\n<P>\nWow, that was way easier than doing it in C++!\n<\/P>\n<P>\nThat program searches one folder,\nbut let&#8217;s say we want to do a full recursive search.\nNo problem.\nTake the code we wrote and shove it into a helper function\n<CODE>process&shy;Files&shy;In&shy;Folder<\/CODE>,\nthen call it as part of a recursive directory search.\n<\/P>\n<PRE>\nfunction processFilesInFolder(folder) {\n  var items = folder.Items();\n  var SHCONTF_NONFOLDERS = 64;\n  items.Filter(SHCONTF_NONFOLDERS, &#8220;*.jpg&#8221;);\n  for (var i = 0; i &lt; items.Count; i++) {\n    var item = items.Item(i);\n    if (item.ExtendedProperty(&#8220;System.Rating&#8221;) &gt;= 80) {\n      WScript.StdOut.WriteLine(item.Path);\n    }\n  }\n}<\/p>\n<p>function recursiveProcessFolder(folder) {\n  processFilesInFolder(folder);\n  var items = folder.Items();\n  var SHCONTF_FOLDERS = 32;\n  items.Filter(SHCONTF_FOLDERS, &#8220;*&#8221;);\n  for (var i = 0; i &lt; items.Count; i++) {\n    recursiveProcessFolder(items.Item(i).GetFolder);\n  }\n}<\/p>\n<p>var shell = new ActiveXObject(&#8220;Shell.Application&#8221;);\nvar picturesFolder = shell.Namespace(39);\nrecursiveProcessFolder(picturesFolder);\n<\/PRE>\n<P>\nYou can use this as a jumping-off point for whatever\nyou want to do with your top-rated pictures,\nlike copy them to your digital photo frame.\n<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m not sure if I&#8217;ll be able to keep it up, but I&#8217;m going to see if I can make Monday &#8220;Little Programs&#8221; day, where I solve simple problems with little programs. Today&#8217;s little program is a script that goes through your Pictures folder and picks out your top-rated photos. The key step here is [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-5573","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>I&#8217;m not sure if I&#8217;ll be able to keep it up, but I&#8217;m going to see if I can make Monday &#8220;Little Programs&#8221; day, where I solve simple problems with little programs. Today&#8217;s little program is a script that goes through your Pictures folder and picks out your top-rated photos. The key step here is [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/5573","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=5573"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/5573\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=5573"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=5573"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=5573"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}