Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 490
Registered: ‎07-16-2008
My Device: Not Specified
Accepted Solution

Deleting directory issue

Hello guys'

 

My application creates many directories to file:///store/home/user/App/

 

I want to delete a directory that has files.

 

First step. deleted all files in directory.

Second step. Delete that directory.

 

At the second step, exception throws that net.rim.device.api.io.file.FileIOException: Directory not empty

 

I don't understand why above exception threw.

 

How to solve this problem ?

 

Plz help me guys'

 

Tnx'

Developer
Posts: 19,612
Registered: ‎07-14-2008
My Device: Not Specified

Re: Deleting directory issue

I presume you have deleted all files, including hidden files, with no exceptions and that there is nothing else running in the application or another applicaion on the device that is using that directory?
Developer
Posts: 490
Registered: ‎07-16-2008
My Device: Not Specified

Re: Deleting directory issue

[ Edited ]

My applicatios is using up directory.

In other word,

file:///store/home/user/App/ - my application uses it.

file:///store/home/user/App/Dir1 - current directory (Write file, read file while running application)

file:///store/home/user/App/Dir2 - To delete directory.

 

I want to delete Dir2. There are no hidden files. And other appication is not using it.

 

I think it is possible to delete directory, if there is no file in that directory.

 

And I am using thread to delete directory. The step is :

1. Delete all files in that dir.

2. Delete dir.

 

Maybe BB device recognizes step 1 like that using that directory.

 

Actually I dont know what wrong is.

 

Do you have sample code ? guys'

 

 

Tnx a lot'

 

Message Edited by Raiden on 02-11-2009 05:33 AM
Developer
Posts: 19,612
Registered: ‎07-14-2008
My Device: Not Specified

Re: Deleting directory issue

Are you seeing this on a Simulator or on a Device?  What OS Levels are involved?  Just want to try it for myself.

Developer
Posts: 490
Registered: ‎07-16-2008
My Device: Not Specified

Re: Deleting directory issue

Iam using simulator. JDE 4.2.1.
Developer
Posts: 19,612
Registered: ‎07-14-2008
My Device: Not Specified

Re: Deleting directory issue

Just tried a 4.2.1 compiled code in a 4.5 simulator (sorry, it was the easiest thing to do) and it works fine.  I presume you have deleted all the files and all the directories.  Post the code you use to do this for review if you are still having problems.
Developer
Posts: 490
Registered: ‎07-16-2008
My Device: Not Specified

Re: Deleting directory issue

[ Edited ]

Here is my source code :

 

private void deleteFolder(String fullPath) {
try {
FileConnection dirConn = (FileConnection)Connector.open(fullPath, Connector.READ_WRITE);
if(dirConn.exists() && dirConn.isDirectory()) {
for(Enumeration e = dirConn.list("*.*", true); e.hasMoreElements();) {
String name = e.nextElement().toString();
deleteIOneFile(fullPath + name);
}
dirConn.delete();
}
dirConn.close();
} catch(IOException ioe) {
System.out.println("1 Exception : " + ioe.toString());
}
}

private void deleteIOneFile(String path) {

try {
FileConnection fileConn = (FileConnection)Connector.open(path);
if(fileConn.exists())
fileConn.delete();

fileConn.close();
} catch(IOException ioe) {
System.out.println("2 Exception : " + ioe.toString());
}
}

 

Throws exception that : 1 Exception : net.rim.device.api.io.file.FileIOException: Directory not empty

I don't understand why throws exception.

 

 

Message Edited by Raiden on 02-13-2009 12:56 AM
Developer
Posts: 19,612
Registered: ‎07-14-2008
My Device: Not Specified

Re: Deleting directory issue

Try changing "*.*" to just "*".
Developer
Posts: 490
Registered: ‎07-16-2008
My Device: Not Specified

Re: Deleting directory issue

ok, Tnx' Peter'