1. using an input string from prompt_string

hi there , 

one more question .......... 
sorry for my lack of knowledge ........
but, just new and learning the dir,file stuff etc.

the programme below gives me any file, sub directory, directory etc.

but I have to open the file in the editor 
then type the directory I want the files from .

I wonder how I use the answer to prompt_string 
to get programme 

to output the directory ??

 Is there a line to use ?

********************** below is prompt_string
name takes string
                     now,
 how can 
exit_code understand is the directory I want ??


include file.e
--include file_ln.e         ------------- USE ONE  or  THE OTHER   -------------
NOT Both !!!!!!!
include get.e
constant TRUE=1
object exit_code
integer tabs     tabs=0
atom k,w         k=0
sequence name

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")
    if find('d',entry[D_ATTRIBUTES]) then
       puts(1,"\n\t\t<SUB DIR> ")
    end if
    printf(1,"%s%s\n",{repeat('\t',tabs),entry[D_NAME]})
    if find('d',entry[D_ATTRIBUTES]) then
       puts(1," \n")
       tabs += 1
    end if
    return 0
end function

name = prompt_string("Directory ")
printf(1,"%s\n" ,{name})

exit_code = walk_dir("c:\\'name'", routine_id("look_at"), TRUE)

k=0

w=wait_key()


If it is too difficult ......... O.K. 
         I'll plod on 

But thanks for reading my message 

les.r.

new topic     » topic index » view message » categorize

2. Re: using an input string from prompt_string

Les Rogers wrote:
> 
> 
> hi there , 
> 
> one more question .......... 
> sorry for my lack of knowledge ........
> but, just new and learning the dir,file stuff etc.
> 
> the programme below gives me any file, sub directory, directory etc.
> 
> but I have to open the file in the editor 
> then type the directory I want the files from .
> 
> I wonder how I use the answer to prompt_string 
> to get programme 
> 
> to output the directory ??
> 
>  Is there a line to use ?
> 
> ********************** below is prompt_string
> name takes string
>                      now,
>  how can 
> exit_code understand is the directory I want ??
> 
> 
> include file.e
> --include file_ln.e         ------------- USE ONE  or  THE OTHER  
> -------------
> NOT Both !!!!!!!
> include get.e
> constant TRUE=1
> object exit_code
> integer tabs     tabs=0
> atom k,w         k=0
> sequence name
> 
> 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")
>     if find('d',entry[D_ATTRIBUTES]) then
>        puts(1,"\n\t\t<SUB DIR> ")
>     end if
>     printf(1,"%s%s\n",{repeat('\t',tabs),entry[D_NAME]})
>     if find('d',entry[D_ATTRIBUTES]) then
>        puts(1," \n")
>        tabs += 1
>     end if
>     return 0
> end function
> 
> name = prompt_string("Directory ")
> printf(1,"%s\n" ,{name})
> 
> exit_code = walk_dir("c:\\'name'", routine_id("look_at"), TRUE)
> 
> k=0
> 
> w=wait_key()
> 
> 
> If it is too difficult ......... O.K. 
>          I'll plod on 
> 
> But thanks for reading my message 
> 
> les.r.

If I correctly understand what you are doing, you want to add the contents 
of the sequence name to something (which designates a drive), and then pass
 the resulting sequence to walk_dir()?

If so, just change
exit_code = walk_dir("c:\\'name'", routine_id("look_at"), TRUE)

to 
exit_code = walk_dir("c:\\" & name, routine_id("look_at"), TRUE)


& adds together two sequences together to make a longer one. Yhis is called
the concatenation of the two sequences (a string is just a sequence all 
elements of which are integers small enough to map to printable characters.

HTH
CChris

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

3. Re: using an input string from prompt_string

Les Rogers wrote:
> 
> 
> hi there , 
> 
> one more question .......... 
> sorry for my lack of knowledge ........
> but, just new and learning the dir,file stuff etc.
> 
> the programme below gives me any file, sub directory, directory etc.
> 
> but I have to open the file in the editor 
> then type the directory I want the files from .
> 
> I wonder how I use the answer to prompt_string 
> to get programme 
> 
> to output the directory ??
> 
>  Is there a line to use ?
> 
> ********************** below is prompt_string
> name takes string
>                      now,
>  how can 
> exit_code understand is the directory I want ??
> 
<SNIP> 
> 
> If it is too difficult ......... O.K. 
>          I'll plod on 
> 
> But thanks for reading my message 

It's never too difficult :)
The challenge is the fun!

One simple change..

exit_code = walk_dir(name,routine_id("look_at"),FALSE)

aside from changing the first argument to just name, notice that I changed TRUE
to FALSE. see below


Your look_at() function is not quite right still.
I had assumed you fixed it yourself, since your were satisfied with the code I
posted the other day.

It doesn't unindent, when it leaves a subdirectory.

Using the function the way it is, you will get:
C:\
  C:\subdir1\
    C:\subdir1\file1.txt
    C:\subdir1\subdir2\
      C:\subdir1\subdir2\file2.txt
      C:\subdir3\
        C:\subdir3\file3.txt

What you really want is:
C:\
  C:\subdir1\
    C:\subdir1\file1.txt
    C:\subdir1\subdir2\
      C:\subdir1\subdir2\file2.txt
  C:\subdir3\
    C:\subdir3\file3.txt


Here is the function ya need..
function look_at(sequence path_name,sequence entry)
 integer ret
    ret = 0 -- default exit code
    if k=0 then
       -- it's not a good idea to put multiple statements on one line
       -- the 2nd statement is easily missed
       printf(1,"%s \n\n",{path_name}) k=1
    end if
    puts(1,"\t")
    if find('d',entry[D_ATTRIBUTES]) then
       puts(1,"\n\t\t<SUB DIR> ")
    end if
    printf(1,"%s%s\n",{repeat('\t',tabs),entry[D_NAME]})
    if find('d',entry[D_ATTRIBUTES]) then
       puts(1," \n")
       tabs += 1
       -- recurse into subdirectory
-- we need to walk the subdirectories ourself so we know when they are
       finished
       ret = walk_dir(path_name&"\\"&entry[D_NAME],routine_id("look_at"),FALSE)
       tabs -= 1 -- unindent
    end if
    return ret
end function

-- Using FALSE instead of TRUE, walk_dir() will traverse only the top-level in
the specified directory.
-- Subdirectories are traversed via the look_at() function.

exit_code = walk_dir(name,routine_id("look_at"),FALSE)


Hopefully I got it right this time.

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