Re: dos.e
- Posted by Derek Parnell <ddparnell at bigpond.com> May 18, 2002
- 425 views
Good work, J. Maybe not many people use DOS anymore ----- Original Message ----- From: <jluethje at gmx.de> To: "EUforum" <EUforum at topica.com> Subject: dos.e > > 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() ]=========================== <snip> > > >