Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename folder in SD card

This must be, supposedly, a very simple task, but I've been around it for some time without successes...

In my app I create a folder in the SD card, where I store temporary jpg files. Since I don't want my app to show those temp files when browsing the phone for images, I was trying to make that folder hidden. So, right after creation the dir, I tried to rename it, like this:

String tmppath="/sdcard/myapp/tmp";
try
{
//this creates a directory named TMP -->OK!
 File f=new File(tmppath); 
  if(!f.isDirectory())  
   f.mkdirs();  

//this was supposed to rename the directory to .TMP, but isn't working...

Process process=Runtime.getRuntime().exec("mv "+tmppath +" /sdcard/myapp/.tmp/");
process.waitFor();
}
catch(SecurityException e)
{
}
catch(IOException e)
{
} 
catch (InterruptedException e) 
{
}

Any thoughts?

like image 245
Direz Gunstad Avatar asked Nov 29 '22 18:11

Direz Gunstad


1 Answers

File file = new File("your old file name");
File file2 = new File("your new file name");
boolean success = file.renameTo(file2);
like image 141
Piyush Avatar answered Dec 04 '22 11:12

Piyush