[jcifs] Getting concurrency error when deleting a file

Hugo Palma hugo.m.palma at gmail.com
Tue Mar 3 09:50:21 GMT 2009


Thanks for the tip. Got me thinking about the permissions and i solved it by
changing my code to:

SmbFile folder = new SmbFile("smb://myfolder");
for (String filePath : folder.list()) {
     SmbFile file = new SmbFile(folder.getPath() + filePath, null,
SmbFile.FILE_SHARE_DELETE);

     // do something

    file.delete();
  }

On Tue, Mar 3, 2009 at 1:52 AM, Michael B Allen <ioplex at gmail.com> wrote:

> On Mon, Mar 2, 2009 at 1:46 PM, Hugo Palma <hugo.m.palma at gmail.com> wrote:
> > Hi all,
> > a have a very simple use case where i want to get all the file in a
> > directory, iterate over them a delete a few.
> > My code is something like:
> >
> > SmbFile folder = new SmbFile("smb://myfolder");
> > for (SmbFile file : folder.listFiles()) {
> >     // do something
> >
> >    file.delete();
> > }
> >
> > It seems that if that "do something" doesn't include calling the
> > "getInputStream" method on the file everything goes fine. But if it does
> i
> > get the following error on the delete operation:
>
> I would think that that should still work since I thought
> getInputStream opened the file with a permissible shareAccess. Perhaps
> not.
>
> Anyway, try calling close() on the InputStream before you delete().
>
> Mike
> - Show quoted text -
>
> >
> > jcifs.smb.SmbException: The process cannot access the file because it is
> > being used by another process.
> >         at
> > jcifs.smb.SmbTransport.checkStatus(SmbTransport.java:522)
> >         at
> > jcifs.smb.SmbTransport.send(SmbTransport.java:622)
> >         at
> > jcifs.smb.SmbSession.send(SmbSession.java:239)
> >         at
> > jcifs.smb.SmbTree.send(SmbTree.java:109)
> >         at
> > jcifs.smb.SmbFile.send(SmbFile.java:718)
> >         at
> > jcifs.smb.SmbFile.delete(SmbFile.java:2342)
> >         at jcifs.smb.SmbFile.delete(SmbFile.java:2286)
> >
> >
> > Any idea why this is happening ? Clearly some resource if being left open
> > but i don't see any close method.
> > Thanks
> >
>
>
>
> --
> Michael B Allen
> Java Active Directory Integration
> http://www.ioplex.com/
>
-------------- next part --------------
HTML attachment scrubbed and removed


More information about the jcifs mailing list