dos.e

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

Hi all,

there are some bugs in dos.e (from Archive/Library Routines)
-- tested with Euphoria 2.3:


=============================[ deltree() ]==============================

<code>
global function deltree(string dirname)
   [...]
   if not compare(dirname[length(dirname)], "\\") then
      dirname = dirname[1..length(dirname)-1]
   end if
</code>

The condition   compare(dirname[length(dirname)], "\\")
is *always* -1, because dirname[length(dirname)] is an atom, and
"\\" is a sequence.

So the statement   dirname = dirname[1..length(dirname)-1]   will
*never* be executed, and therefore the function will not work properly,
when called with a dirname that has a backslash at the end.

==> It should be:  if not compare(dirname[length(dirname)], '\\') then
    or (clearer):  if dirname[length(dirname)] = '\\' then

----------------------------------------

Also in function deltree:

<code>
   info = dir(dirname)
   [...]
   if not match(info[loop][D_ATTRIBUTES],"d") then
      i = delete(dirname & "\\" & info[loop][D_NAME])
</code>

For a normal file, info[loop][D_ATTRIBUTES] is "", and then the error
"first argument of match() must be a non-empty sequence" is raised.
(BTW: I think this information should be included in the documentation
      for match().)

Furthermore, eg match("da", "d") = 0, which means that the routine will
try to delete() a directory with the attributes "da", for instance
(which will not work, of cause).

==> It should be:  if not find('d', info[loop][D_ATTRIBUTES]) then

----------------------------------------
This is my modified deltree() function:
----------------------------------------

global function deltree (string dirname)
   object info
   integer i

   if dirname[length(dirname)] = '\\' then
      dirname = dirname[1..length(dirname)-1]
   end if
   info = dir(dirname)
   if atom(info) then
      return false
   end if
   if length(info) < 3 then
      return rmdir(dirname)
   end if
   info = info[3..length(info)]
   for loop = 1 to length(info) do
      if not find('d', info[loop][D_ATTRIBUTES]) then
         i = delete(dirname & "\\" & info[loop][D_NAME])
         if not i then
            return false
         end if
      else
         i = deltree(dirname & "\\" & info[loop][D_NAME])
         if not i then
            return false
         end if
         i = rmdir(dirname & "\\" & info[loop][D_NAME])
      end if
   end for
   return rmdir(dirname)
end function


==============================[ rename() ]==============================

<code>
global function rename(string oldname, string newname)
   [...]
   if (not compare(oldname[2],":")) and (not compare(newname[2],":")) 
then
</code>

==> It should be:  if oldname[2] = ':' and newname[2] = ':' then
(see above)


==========================[ documentation() ]===========================

There is an error in the documentation at the beginning of the file:

<snip>
-- 
--          Moves file old to new. Can be used as rename among 
different     --
--          disk drives.                                                     
-- 
-- 
--          Renames file old to new.                                         
-- 
--          NOTE: Can't rename among different disk drives                   
-- 

Either both move() and rename() can work among different disk drives, or
both can't. The only thing move() does, is calling rename().


Best regards,
   Juergen

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

Search



Quick Links

User menu

Not signed in.

Misc Menu