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.

Here is some example code, written using Euphoria v4 ...

include std/filesys.e 
include std/sort.e 
include std/io.e 
 
function process_file(sequence path_name, sequence item) 
-- this function accepts two sequences as arguments 
-- it displays all C/C++ source files and their sizes 
    if find('d', item[D_ATTRIBUTES]) then 
        return 0 -- Ignore directories 
    end if 
    sequence t 
 
	t = fileext(item[D_NAME]) 
    if not find(t, {"c","h","cpp","hpp","cp"}) then 
        return 0 -- ignore non-C/C++ files 
    end if 
    writefln(1, "[][][]: [] []/[z:2]/[z:2] [z:2]:[z:2]:[z:2].[z:3]",  
    		{path_name, {SLASH}, item[D_NAME], item[D_SIZE], 
             item[D_YEAR], item[D_MONTH], item[D_DAY], 
             item[D_HOUR], item[D_DAY], item[D_SECOND], item[D_MILLISECOND]}) 
    return 0 -- keep going 
end function 
 
function my_dir(sequence path) 
    object d 
	 
    d = dir(path) 
    if atom(d) then 
        return d 
    end if 
    -- Sort in ascending time stamp. 
   return sort_columns(d, {D_YEAR, D_MONTH, D_DAY,  
                           D_HOUR, D_MINUTE, D_SECOND, D_MILLISECOND}) 
end function 
 
integer exit_code  
sequence cmds 
 
cmds = command_line() 
exit_code = walk_dir(cmds[3], routine_id("process_file"), 1, routine_id("my_dir")) 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu