Replacing <SearchValue> with a codeblock should take care of that problem:
nPosition := hb_AScan( aFiles, { |aVal| ".bak" $ lower( aVal[ F_NAME ] )
}, nPosition )
Whether it is efficient with hundreds of thousands of files is a
different question :-)
Hi Pete,
Oh, by the way, you should probably adjust the condition a little or
petes.bakery.jpg will be lost :-)
Hi Pete, try this:
procedure main
setmode(25,80)
clear
aDir := DIRECTORY("v:\sorgenti\hmg\test\*.*", "HSD")
adirlen:=len(aDir)
nDeleted:=0
altd()
? "aDir, elements:"+str(adirlen)
// for some reason this does not work
//aeval(aDir,{|x|iif(lower(right(x[1],4))==".bak",x:=nil,nil)} )
aeval(aDir,{|x,y|mydel(y)} )
? "deleted:"+str(nDeleted)
asize(aDir,adirlen-nDeleted)
? "new size:"+str(len(aDir))
wait
return
function mydel(n)
if lower(right(aDir[n,1],4))==".bak"
? aDir[n,1]
aDir[n]=nil
++nDeleted
endif
return nil
Dan
You can check hb_A · Petewg/harbour-core Wiki · GitHub for parameter options to hb_Ascan
Changes:1. Specify the beginning of the search in ASCAN2. Change the order of Right(Lower(... to Lower(Right(... since performing a lower to a small number of characters should be faster than to a large number of characters and we are looking for speed!
Ouch, f[1], I can smell a magic number there. Give me a minute to
recover from the shock ... :-)
Maybe AEval() could be of help there?
One thing you haven't mentioned yet is what you plan to do with the
array after you have cleaned it.
Would it be possible to replace the
sub-arrays that you don't want to keep with NIL, for example, and then
ignore the NIL elements in whatever your next step is?
Another thought might be to skip Directory() altogether and replicate
what it does using FileFindFirst() and FileFindNext() from
contrib\hbmisc\ffind.c and check with FileFindName() if the name of each
file found meets your non-".bak" criteria. After all, the combination of
FileFindFirst() and FileFindNext() does the same thing as Directory()
does regarding the search. But you would have to pick up the file names
etc yourself and build the array. You can pre-allocate empty array
elements in chunks of 100 or 1000 or whatever you like instead of
AAdd()ing each element separately. There will of course be a lot of
calls to HB_FUNC level functions, but there will be no need to delete
elements and shrink the array. You would have to first build an array of
directory names using hb_DirScan(). In the end, I am not sure if all the
work will pay off, but at least it should be doable :-)
is hb_ADel() the same as hb_arrayDel() ?if yes as i can say it does NOT "remove" Item ... it will be NIL
p.s. why not "include" matching files instead of "remove" ...
Hi Dan,
Oh yes! Good clipper code! ;-) plain and pure and a nostalgic coding-trip
back to glorious eighties and nineties, much appreciated and enjoyed, indeed.
Thanks!
btw, I'm not sure that the elements set to nil are placed at the end of the array, as per aDel(), so maybe it's necessary, before the aSize(), an aSort(...)
The problem with aeval() is that you can't delete directly an element with hb_adel(arr,pos,.t.), that would skip an element and give an error (array access) because the array then is shorter but aeval will try to process the original number of elements.
Maybe aeval(aDir,{|x,y|iif(lower(right(x[1],4))==".bak",adel(aDir,y),nil)} )
The trick is to set the elements containing .bak to nil, and then remove all of them.
It would be interesting to check which code is faster wit BIG arrays.
Dan
--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-users/8fb077d7-a8dc-4f31-8c0f-6bed75a215f0n%40googlegroups.com.