Re: Help needed with walk_dir()

new topic     » goto parent     » topic index » view thread      » older message » newer message
hacker said...

It might help if I explain what I want to do first. I would like to select a file from a folder, and then use walk_dir() to select and process all files in the same directory, but in a particular order based on the timestamp of the file. So I will select the oldest and then need the program to select progressively "newer" files which will be processed in turn.

The default in walk_dir() is to visit files in alphabetical order, and the manual says if you want to use a different order you should:

"set the global integer my_dir to the routine id of your own modified dir() function that sorts the directory entries differently. See the default dir() function in file.e."

I've looked at the example in "search.ex" but I'm not sure how to write the dir() function which will achieve what I want. Do I need to use custom_sort()? Any help appreciated, thanks in advance!

Basically, walk_dir() will call a function to sort the directory listing. By default it uses sort() which sorts in alpabetical order.

You can write your own sort function from scratch to sort the directory listing differently (or, if you don't want to sort at all, use the following identity function to tell walk_dir() to not sort at all but use the "native" order:)

function identity(object x) 
return x 
end function 
constant identity_id = routine_id("identity") 

You can use custom_sort() with walk_dir() if you want. custom_sort() requires that you write a comparator function (that looks at two directory entries and decides which one is greater than the other), and uses that to determine how to sort the directory listing.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu