1. Please help with Formatting Programme Output

This programme prints all directories and all files 
in directory and all sub-directories and files :-

include file.e
include get.e
constant TRUE=1
object exit_code
atom k,w
     k=0

function look_at(sequence path_name,sequence entry)
    if k=0 then printf(1,"%s\n\n",{path_name}) k=1 end if
    puts(1,"\t")
    printf(1,"%s",{entry[D_NAME]})
    puts(1,"\n")
    return 0
end function

exit_code=walk_dir("c:\\", routine_id("look_at"),TRUE)
k=0
w=wait_key()

Format I would like is :-

Directory name
   files                   ...........  indented as shown
   
      Sub-Directory          ........ indented as shown
         files                 ...........  indented as shown

Next Directory Name
   files 

      Sub-Directory
         files

                               etc.

I don't know how to tell the computer when a new directory is there 
and how to distinguish a file from a directory ??????

         if it is too difficult then O.K.

Thank you for taking time to read my message .

les.r.

new topic     » topic index » view message » categorize

2. Re: Please help with Formatting Programme Output

Les Rogers wrote:
> 
> 
> This programme prints all directories and all files 
> in directory and all sub-directories and files :-
> 
> include file.e
> include get.e
> constant TRUE=1
> object exit_code
> atom k,w
>      k=0
> 
> function look_at(sequence path_name,sequence entry)
>     if k=0 then printf(1,"%s\n\n",{path_name}) k=1 end if
>     puts(1,"\t")
>     printf(1,"%s",{entry[D_NAME]})
>     puts(1,"\n")
>     return 0
> end function
> 
> exit_code=walk_dir("c:\\", routine_id("look_at"),TRUE)
> k=0
> w=wait_key()
> 
> Format I would like is :-
> 
> Directory name
>    files                   ...........  indented as shown
>    
>       Sub-Directory          ........ indented as shown
>          files                 ...........  indented as shown
> 
> Next Directory Name
>    files 
> 
>       Sub-Directory
>          files
> 
>                                etc.
> 
> I don't know how to tell the computer when a new directory is there 
> and how to distinguish a file from a directory ??????
> 
>          if it is too difficult then O.K.
> 
> Thank you for taking time to read my message .
> 
> les.r.

integer tabs
tabs = 0

function look_at(sequence path_name,sequence entry)
    if k=0 then printf(1,"%s\n\n",{path_name}) k=1 end if
    printf(1,"%s%s\n",{repeat('\t',tabs),entry[D_NAME]})
    if find('d',entry[D_ATTRIBUTES]) then
      tabs += 1
    end if
    return 0
end function


hope that helps

Chris Bensler
~ The difference between ordinary and extraordinary is that little extra ~
http://empire.iwireweb.com - Empire for Euphoria

new topic     » goto parent     » topic index » view message » categorize

3. Re: Please help with Formatting Programme Output

Chris Bensler wrote:

I made a mistake.
repeat() will not accept a zero count (as would be in the first call to
look_at())

Easy fix:
function repeat0(object x, integer count)
  if count then
    return repeat(x,count)
  else
    return ""
  end if
end function

integer tabs
tabs = 0

function look_at(sequence path_name,sequence entry)
  if k=0 then printf(1,"%s\n\n",{path_name}) k=1 end if
  printf(1,"%s%s\n",{repeat0('\t',tabs),entry[D_NAME]})
  if find('d',entry[D_ATTRIBUTES]) then
    tabs += 1
  end if
  return 0
end function

Chris Bensler
~ The difference between ordinary and extraordinary is that little extra ~
http://empire.iwireweb.com - Empire for Euphoria

new topic     » goto parent     » topic index » view message » categorize

4. Re: Please help with Formatting Programme Output

Chris Bensler wrote:
> Chris Bensler wrote:
> I made a mistake.
> repeat() will not accept a zero count (as would be in the first call to
> look_at())

You didn't make a mistake.
repeat(x, 0) works as you would expect.
It returns the empty (length-0) sequence: {} (equivalent to "")
 
> Easy fix:
> function repeat0(object x, integer count)
>   if count then
>     return repeat(x,count)
>   else
>     return ""
>   end if
> end function

Not necessary!

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

new topic     » goto parent     » topic index » view message » categorize

5. Re: Please help with Formatting Programme Output

Robert Craig wrote:
> 
> Chris Bensler wrote:
> > Chris Bensler wrote:
> > I made a mistake.
> > repeat() will not accept a zero count (as would be in the first call to
> > look_at())
> 
> You didn't make a mistake.
> repeat(x, 0) works as you would expect.
> It returns the empty (length-0) sequence: {} (equivalent to "")

Interesting. I don't know why I thought that.

Chris Bensler
~ The difference between ordinary and extraordinary is that little extra ~
http://empire.iwireweb.com - Empire for Euphoria

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu