View Single Post
  #51  
Old August 12th 18, 07:18 PM posted to alt.comp.freeware,alt.comp.os.windows-10
Terry Pinnell[_3_]
external usenet poster
 
Posts: 732
Default Sort files by aspect ratio?

Paul wrote:
[i]
Terry Pinnell wrote:
Paul wrote:

Terry Pinnell wrote:
Paul wrote:

Terry Pinnell wrote:
"B. R. 'BeAr' Ederson" wrote:

On Tue, 07 Aug 2018 12:27:21 +0100, Terry Pinnell wrote:

Anyone know of a tool or hack that will do something that Win 10 File
Explorer unfortunately cannot: sort a folder of files into aspect ratio
(width/height)?
Although I still think, Dimensions2Folder is best suited for your needs,

http://www.dcmembers.com/skwire/down...ions-2-folders

maybe you like Arti from the same author even better:

http://www.dcmembers.com/skwire/download/arti

Be sure to (really) try both of them. They are no-install portable.

F-Up set to acf.
BeAr
Thanks BeAr, Dimensions2Folder is a nice tool and it does indeed do what
I want. And on brief acquaintance it has the advantage of being over
three times faster than Mayayana's VBS script. For example, my test
folder of 100 files took 4 s.

Did you try Arti? It appears to be unstable here in Version 1803 (build
17134.167). A few seconds after dragging a folder or multiple files, it
closes unceremoniously.

Terry, East Grinstead, UK
A faster way to get the picture information, would be
to consult Windows.edb instead.

This is a tech demo, not a complete application.
It generates a CSV file which shows all the
images on the path in the SCOPE. Adjust the SCOPE
string to reflect where your image collection is on
disk. If you set the scope to "C:\" then you'll
pick up every 1x1 pixel picture ever invented :-)

What this is doing, is leveraging the three hours spent
by the Windows Search indexer, on your image collection
already.

Yes, you've seen this script before, in a previous
question. I just tweaked it a little bit. You run this
from a "regular user" Powershell. cd to the directory
containing the script, then run it. Powershell will not
run a file from the current working directory, unless
the dot is in front, as shown. I'm not a Powershell
expert, so am not going to be able to dig you out
of trouble all that easily. I'm a "copy/paste expert" :-/
If I can do it with copy/paste, I will.

########### ./little_bobby_tables2.ps1 ################################
#
# Inspiration: https://www.petri.com/how-to-query-t...and-powershell
#
# (Commented out text, is either outright failed stuff, or variants you can test)
#
# At the bottom line, pick a more imaginative filename...
#
# Hint - the less formatting you do in PowerShell, the faster the script runs.
#
# The CSV can be pulled into Excel, LibreOffice Calc, or Notepad.
#
################################################## ####################

$sql = "SELECT System.ItemFolderPathDisplay, `
System.ItemName, `
System.Image.HorizontalSize, `
System.Image.VerticalSize FROM SYSTEMINDEX `
WHERE System.Image.HorizontalSize0 AND `
System.Image.VerticalSize0 AND `
SCOPE='C:\users\Terry Pinnell\Downloads'"

$provider = "provider=search.collatordso;extended properties=’application=windows’;"

$connector = new-object system.data.oledb.oledbdataadapter -argument $sql, $provider

$dataset = new-object system.data.dataset

if ($connector.fill($dataset)) { $dataset.tables[0] | Export-CSV little.bobby.tables.4.csv }

########### end of ./little_bobby_tables2.ps1 ##########################

Paul
Thanks, but I'm having trouble at the first hurdle. Haven't enough time
right now to plunge into learning the basics of Powershell. But as a
start I copy pasted your entire text to my editor and saved it in
C:\Users\terry\Dropbox\Scripts as
./little_bobby_tables2.ps1
(I assumed that's a lower case letter 'l', not the number '1'? But I've
tried both. Neither look like legitimate filenames...

I opened a PS window. What should I now type on the command line to run
that script file? Or how should I rename it?

Terry, East Grinstead, UK
You can rename it to "powertst.ps1" if you want.
That's Pee Esse One as a file extension.

I didn't invent that extension. Microsoft did.

1) Open a Powershell window.

2) .\powertst.ps1

Then open the output file that's been dumped
into the same directory. You could change the
name in the script from "little.bobby.tables.4.csv"
if you want. You could use "powertst.csv" if you
wanted, to make the name shorter.

Paul


A very useful learning exercise, thanks. I now know how to run a
copy/pasted PS1 script. But not a practical route to a solution, as it
delivers only a CSV file, not a folder of selected or renamed files.

BeAr's recommended solution, Dimensions2Folders, is the one I've started
using. But it will also be interesting to see the AWK/GAWK script
Reinhard is developing.

Terry, East Grinstead, UK


Here's my project.
Two files.
The awk file uses Gawk 3.

The binaries link from this page, has the executable.

http://gnuwin32.sourceforge.net/packages/gawk.htm

Gawk calls powershell, to do the database query.
Powershell has a set-executionpolicy, which would
normally be set to "UnRestricted" for home usage.

I had trouble calling Powershell, using the normal technique.
However, to my shock and horror, the shell allows override
being passed to it directly.

powershell -executionpolicy bypass -file query.ps1

It's only running as a regular user, so there's no "elevation
attack" so far by doing this. In any case, mines running :-/

**************** Helper script "query.ps1" ********************
# powershell -file query.ps1 -TREEDIR "'C:\'"

param([string]$TREEDIR="'C:\'")

$sql = "SELECT System.ItemFolderPathDisplay, `
System.ItemName, `
System.Image.HorizontalSize, `
System.Image.VerticalSize FROM SYSTEMINDEX `
WHERE System.Image.HorizontalSize0 AND `
System.Image.VerticalSize0 AND `
SCOPE=$TREEDIR"

$provider = "provider=search.collatordso;extended properties=’application=windows’;"
$connector = new-object system.data.oledb.oledbdataadapter -argument $sql, $provider
$dataset = new-object system.data.dataset
if ($connector.fill($dataset)) { $dataset.tables[0] | Export-CSV query.csv }
**************** end of Helper script "query.ps1" **************

**************** "skimmer.awk" ********************
# gawk -f skimmer.awk width height percent scan_path out_dir
#
# gawk -f skimmer.awk 16 9 1 "C:\\" "C:\users\user name\downloads\outdir" NUL
#
# 0 1 2 3 4 5 (no input file)
#
# ARGC = 6 ARGV[0] .. ARGV[5]
#
# query.csv looks like this, skip the first two lines. There can be commas in the filename!
#
# #TYPE System.Data.DataRow
# "SYSTEM.ITEMFOLDERPATHDISPLAY","SYSTEM.ITEMNAME"," SYSTEM.IMAGE.HORIZONTALSIZE","SYSTEM.IMAGE.VERTICA LSIZE"
# "C:\Users\user name\Downloads\JPG2","0000014994_1.jpg","669","600 "
# "C:\Users\user name\Downloads\JPG2","04.jpg","500","375"
#
################################################# ##########################
# This is a first cut script, with no error handling or disaster proofing!
# No warranty expressed or implied. Paul.

BEGIN {
if (ARGC != 6) {
print "Usage: width height percent_tol source_tree destdir"
print "gawk -f skimmer.awk 16 9 1 " "\"C:\\\\\" " "\"C:\\users\\user name\\downloads\\outdir\" NUL"
print ""

print "The program needs five arguments."
print "In some cases, two backslashes may be required on the end of a path, to work."
print "This proof print will then show one backslash as having made it through."
print ""
for (i = 1; i ARGC; i++) print ARGV[i]
exit 0
} else {
print "Called with"
print ""
for (i = 1; i ARGC; i++) print ARGV
print ""
width = ARGV[1]+0
height = ARGV[2]+0
percent = ARGV[3]+0
outdir = ARGV[5]
}

# houseclean before run - no collision protection, run one copy only!

cmd = "\"del query.csv\""
system( cmd )

cmd = "\"powershell -executionpolicy bypass -file query.ps1 -TREEDIR \"'" ARGV[4] "'\"\""
print "Query: " cmd
print ""
system( cmd )

# You can redirect stderr ("2") output to clean the output a bit.
# Here, I'm hiding the warning that the directory already exists.

cmd = "\"md \"" outdir "\" 2NUL\""
print "Cmd: " cmd
print ""
system( cmd )

high = width/height * (1 + percent/100)
low = width/height * (1 - percent/100)

if ( (high 0) || (low 0) ) exit 0

i=0
j=0

# No FPAT in Gawk3

FS="\""
while ( (getline "query.csv") 0 ) {
if ( i = 2 ) {

# "C:\Users\xxxx yyyyyyy\Downloads\JPG2","04.jpg","500","375"
# 2 3 4 5 6 7 8
aspect = $6/$8
if ( (high = aspect) && (low = aspect) ) {
print $4 " = " $6 " " $8
cmd = "\"copy \"" $2 "\\" $4 "\" \"" outdir "\"\""
print "Cmd: " cmd
system( cmd )
j++
}
}
i++
}
print i " images in tree, of which " j " got copied"
close( "query.csv" )
# The following jazz not required now, as the program has no other clauses
delete ARGV[5]
delete ARGV[4]
delete ARGV[3]
delete ARGV[2]
delete ARGV[1]
}

#END {
# print "Processed " i " lines"
#}
************* end of "skimmer.awk" ****************

HTH,
Paul


Meanwhile these are the steps I tried.

1. Unwilling to test on my very large \Downloads folder I made a global
replacement of 'downloads' by 'Test 10 for 169' in skimmer.awk and
copied my test folder to C:\Users\terry\Test 10 for 169.
But I don't know what to do to these lines:
# "C:\Users\terry\Test 10 for 169\JPG2","0000014994_1.jpg","669","600"
# "C:\Users\terry\Test 10 for 169\JPG2","04.jpg","500","375"

2. I ran skimmer.awk anyway but could see no obvious result. What
*should* I see?

Terry, East Grinstead, UK

Ads