Re: File Listing

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

C.K. Lester writes:

> I need a program that will output a file list,
> including subfolders...
> kinda like this:
> Forms <dir>
>    Texas <dir>
>        doc1.doc
>        doc2.doc
>    New York <dir>
>        doc3.doc
>        doc4.doc
>    California <dir>
>        doc2.doc
>        doc4.doc

That sounds like a job for walk_dir()...

-- list.ex - display files in a directory and subdirectories
-- usage: ex list directory
-- e.g. ex list .
--        ex list \windows

include file.e

sequence start_dir, list, cl

cl = command_line()
start_dir = cl[3]
list = {}

function save_name(sequence path_name, sequence entry)
-- called by walk_dir() for each file and directory
    sequence file_name

    file_name = entry[D_NAME]
    if find('d', entry[D_ATTRIBUTES]) then
        file_name &= '\\'
    end if
    for i = 1 to length(path_name) do
        if path_name[i] = '\\' then
            file_name = "  " & file_name
         end if
    end for
    -- we could simply print the name, but let's make a list
    list = append(list, file_name)
    return 0 -- keep going
end function

if walk_dir(start_dir, routine_id("save_name"), 1) != 0 then
    puts(2, "walk_dir failed!\n")
end if

-- display the results
for i = 1 to length(list) do
    puts(1, list[i] & '\n')
end for

Regards,
   Rob Craig
   Rapid Deployment Software
   http://www.RapidEuphoria.com

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

Search



Quick Links

User menu

Not signed in.

Misc Menu