[comp.sys.amiga] DeleteFile

JRH4373@TAMVENUS.BITNET (07/27/87)

[Go ahead...eat my line!]
Time for another question.  I am experiencing a bit of difficulty with the
AmigaD*S function DeleteFile().  The documentation I have states that this
function will delete a file or directory.  The problem is, in an application
I am writing, I am getting an object in use error when trying to delete any
directory after having deleted all files in that directory.  The files all
delete fine, but when an attempt is then made to delete the directory, I get
the error.  Keep in mind that this is a directory that my program has recently
created using mkdir() and no other processes are active.  Upon exiting the
program, the del command will not delete it either although I can cd to it.
Only by rebooting the system will the harddisk mount clean up the directory
to allow it to be deleted.  I am sure I must be missing some trivial tidbit
of knowledge concerning deleting files, but I have looked till I am blue in
the face and have failed to find anything that solves this problem.
Anyone out there have any idea what I am doing wrong?
******************************************************************************
Joel << Hatchet >> Hall
jrh4373@tamvenus
I think therefore I am...an Amiga user.
Disclaimer:  I would disclaim my existance, but if I didn't exist, I wouldn't
need to disclaim anything.  So if I don't disclaim something, does that mean I
don't exist...
     
     

bryce@COGSCI.BERKELEY.EDU (Bryce Nesbitt) (07/28/87)

In article <02JRH437@TAMVENUS> JRH4373@TAMVENUS.BITNET writes:
>Time for another question.  I am experiencing a bit of difficulty with the
>AmigaD*S function DeleteFile().
>[I make a directory with mkdir(), but when I try to delete it I get an
>"object in use" error.]

The mkdir() function eventually calls the AmigaDOS CreateDir() function.
CreateDir() returns a lock on the directory in question.  It has an open
lock, thus is "in use".
To delete that directory you must first UnLock() it.  Since you are using
the direct dos DeleteFile(), you should probably also use the direct
dos CreateDir() and UnLock().


|\ /|  . Ack! (NAK, EOT, SOH)
{o O} . 
( " )	bryce@cogsci.berkeley.EDU -or- ucbvax!cogsci!bryce
  U	"Success leads to stagnation; stagnation leads to failure."

daveh@cbmvax.UUCP (Dave Haynie) (07/28/87)

in article <02JRH437@TAMVENUS>, JRH4373@TAMVENUS.BITNET says:
> 
> [Go ahead...eat my line!]
> Time for another question.  I am experiencing a bit of difficulty with the
> AmigaD*S function DeleteFile().  The documentation I have states that this
> function will delete a file or directory.  The problem is, in an application
> I am writing, I am getting an object in use error when trying to delete any
> directory after having deleted all files in that directory.  The files all
> delete fine, but when an attempt is then made to delete the directory, I get
> the error.  Keep in mind that this is a directory that my program has recently
> created using mkdir() and no other processes are active.  

Sounds to me like your "mkdir()" function isn't releasing the FileLock that
the DOS level CreateDir() function returns.  As long as there's a FileLock
still around on a file of any kind, DeleteFile() will refuse to delete it.

If you can find this lock (prehaps your mkdir() returns it), UnLock() it
and then try deleting the directory; you shouldn't have any trouble.  If
this doesn't work, maybe you should throw out the mkdir() function and
go straight to the DOS CreateDir() call, since you're going to direct
DOS calls anyway with DeleteFile().

> Anyone out there have any idea what I am doing wrong?
> ******************************************************************************
> Joel << Hatchet >> Hall
-- 
Dave Haynie     Commodore-Amiga    Usenet: {ihnp4|caip|rutgers}!cbmvax!daveh
"The A2000 Guy"                    PLINK : D-DAVE H             BIX   : hazy
     "Catch a wave and you're sittin' on top of the world" -Beach Boys

mph@rover.UUCP (Mark Huth) (07/29/87)

In article <02JRH437@TAMVENUS> JRH4373@TAMVENUS.BITNET writes:
>Time for another question.  I am experiencing a bit of difficulty with the
>AmigaD*S function DeleteFile().  The documentation I have states that this
>function will delete a file or directory.  The problem is, in an application
>I am writing, I am getting an object in use error when trying to delete any
>directory after having deleted all files in that directory.  The files all
>Joel << Hatchet >> Hall
>jrh4373@tamvenus

There are three reasons that I know of that produuce this result.
	1) The object is in use because your current directory is that
		directory.
	2) The object is in use because an ASSIGN uses that directory
	3) There is an outstanding lock on the directory.

Any other information would be useful.

Mark Huth - I speak for myself
seismo!noao!mcdsun!nud!rover!mph

Actually, they would all seem to be cases of #3.

cmcmanis%pepper@Sun.COM (Chuck McManis) (07/30/87)

In article <02JRH437@TAMVENUS> JRH4373@TAMVENUS.BITNET writes:
				^-How do you remember a user-id like this?
>                        ... I am experiencing a bit of difficulty with the
>AmigaD*S function DeleteFile()...
>       ...  I am getting an object in use error when trying to delete any
>directory after having deleted all files in that directory...
>      ...the del command will not delete it either although I can cd to it.

I suspect you have a LOCK associated with this directory lying around
somewhere. Make sure you UnLock() any directory (or Close()) before
trying to delete it, since AmigaDOS checks the list of Locks off a 
file to determine if it is in use. If you have freed all you locks then
check to see if some other process has it locked. For instance when you 
CD to a directory, the CLI gets a Lock on it, thus it is undeletable until
you CD out of it.

--Chuck McManis
uucp: {anywhere}!sun!cmcmanis   BIX: cmcmanis  ARPAnet: cmcmanis@sun.com
These opinions are my own and no one elses, but you knew that didn't you.