Re: walk_dir() problem, please help debug

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

Marcus,

The problem seems to be that you aren't stripping the line terminator ('\n')
from the lines you are reading from the file and this is messing up the
library routines.  I have also added code to eliminate blank lines.

The corrected program:

with trace

trace(0)

include file.e
include get.e

constant TRUE=1

sequence watchdirs
sequence this_dir
sequence subdir
sequence path
sequence topdir

-- topdir ="" don't need this for the code here
watchdirs = {}
this_dir = ""
path = ""
subdir = ""

-- Begin

-- This function accepts two sequences as arguments
function look_at(sequence path_name, sequence entry)

printf (1, "Checking:%s\\%s\n", {path_name, entry[D_NAME]})

-- keep going
    return 0

end function


-- Read watchdirs from text file into a sequence
integer watchfile,len
object line

watchfile = open("watchit.txt","r")
if watchfile = -1 then
    puts(1, "Couldn't open watchit.txt\n")
    abort(1)
end if

while 1 do
    line = gets(watchfile)
    if atom(line) then
        exit   -- -1 is returned at end of file
    end if
    len=length(line)
    while len>0 do
      if not find(line[len],"\r\n") then exit end if
      len-=1
      line=line[1..len]   -- strip line teminators
    end while
    if len>0 then  -- ignore empty lines
      watchdirs = append(watchdirs, line)
    end if
end while

close (watchfile)


-- Print out watchdirs

for i = 1 to length(watchdirs) do
printf (1, "\n watchdir:%s\n", {watchdirs[i]})
end for

-- Call routine to walk dir ---

-- Copy watchdir[1], kept getting errors about sequences inside strings
-- the copy step is not necessary
-- if you need it for elsewhere in the program, use
-- topdir=watchdirs[1]

--for i = 1 to length(watchdirs[1]) do
--topdir &= watchdirs[1][i]
--end for

--if walk_dir(topdir, routine_id("look_at"), TRUE) then
for i=1 to length(watchdirs) do
-- added, assuming the reason for gettting multiple directory names
-- from the file is to watch them all.
   if walk_dir(watchdirs[i], routine_id("look_at"), TRUE) then
   end if
end for

-- Wait for key ---
puts(1,"Press a key to continue.\n")
integer key
key = wait_key()
--------------------------------------

-- Mike Nelson

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

Search



Quick Links

User menu

Not signed in.

Misc Menu