B
bjarthur
i have (see below) what i think is a fairly simple algorithm, but yet
it doesn't work. given a directory with consecutively numbered jpeg
files (1.jpg, 2.jpg, 3.jpg...), it is designed to count how many files
there are using a binary search. it uses the onload and onerror event
handlers of the image object to see if the files successfully loaded or
not. testing on a macintosh (os x 10.3.8) with a directory of 39
files, IE 5.2 and firefox 1.0 both give the correct answer of 39.
strangely, two other gecko variants (mozilla 1.7.5 and camino 0.8.2)
give 64: for some reason the onerror call does not work properly.
safari 1.2.4 gives infinity. anyone have any ideas?
thanks in advance.
ben
<HTML>
<HEAD>
<SCRIPT>
var my_img, last_num, low, high;
function find_last_img_guts4(filename) {
if((low+1)!=high) {
last_num=(low+high)/2;
my_img=new Image();
my_img.onload = function() { find_last_img_guts3(filename); };
my_img.onerror = function() { find_last_img_guts2(filename); };
my_img.src=filename+"/"+last_num+".jpg"; }
else {
last_num=low; } }
function find_last_img_guts3(filename) {
low=last_num;
find_last_img_guts4(filename); }
function find_last_img_guts2(filename) {
high=last_num;
find_last_img_guts4(filename); }
function find_last_img_guts1(filename) {
low=last_num;
last_num*=2;
my_img=new Image();
my_img.onload = function() { find_last_img_guts1(filename); };
my_img.onerror = function() { find_last_img_guts2(filename); };
my_img.src=filename+"/"+last_num+".jpg"; }
function find_last_img(filename) {
last_num=1;
find_last_img_guts1(filename); }
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT>
find_last_img("test.dir");
document.write("<A
HREF='javascript:alert(last_num);'>alert(last_num)<\/A>");
</SCRIPT>
</BODY>
</HTML>
it doesn't work. given a directory with consecutively numbered jpeg
files (1.jpg, 2.jpg, 3.jpg...), it is designed to count how many files
there are using a binary search. it uses the onload and onerror event
handlers of the image object to see if the files successfully loaded or
not. testing on a macintosh (os x 10.3.8) with a directory of 39
files, IE 5.2 and firefox 1.0 both give the correct answer of 39.
strangely, two other gecko variants (mozilla 1.7.5 and camino 0.8.2)
give 64: for some reason the onerror call does not work properly.
safari 1.2.4 gives infinity. anyone have any ideas?
thanks in advance.
ben
<HTML>
<HEAD>
<SCRIPT>
var my_img, last_num, low, high;
function find_last_img_guts4(filename) {
if((low+1)!=high) {
last_num=(low+high)/2;
my_img=new Image();
my_img.onload = function() { find_last_img_guts3(filename); };
my_img.onerror = function() { find_last_img_guts2(filename); };
my_img.src=filename+"/"+last_num+".jpg"; }
else {
last_num=low; } }
function find_last_img_guts3(filename) {
low=last_num;
find_last_img_guts4(filename); }
function find_last_img_guts2(filename) {
high=last_num;
find_last_img_guts4(filename); }
function find_last_img_guts1(filename) {
low=last_num;
last_num*=2;
my_img=new Image();
my_img.onload = function() { find_last_img_guts1(filename); };
my_img.onerror = function() { find_last_img_guts2(filename); };
my_img.src=filename+"/"+last_num+".jpg"; }
function find_last_img(filename) {
last_num=1;
find_last_img_guts1(filename); }
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT>
find_last_img("test.dir");
document.write("<A
HREF='javascript:alert(last_num);'>alert(last_num)<\/A>");
</SCRIPT>
</BODY>
</HTML>