Win a copy of Clojure in Action this week in the Clojure forum!
    Bookmark Topic Watch Topic
  • New Topic

URGENT :- Hide folder / file using Java

 
Rohit Bhagwat
Ranch Hand
Posts: 205
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hello friends

Can anyone tell me how to hide file or folder using java.

Waiting for your reply...

Thanks and Regards
Rohit
 
Arto Pastinen
Ranch Hand
Posts: 79
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
Rename file so, that it starts with dot.

example:
"myfolder" => ".myfolder"

Same works with files.

.. of course this works only in linux, or maby in mac&solaris, not sure.

- Artsi
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13047
6
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hide in what sense? Hide from the operating system user or hide from Java code that uses java.io.File to get file listings?
Bill
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
http://faq.javaranch.com/view?HowToAskQuestionsTheSmartWay
 
Rohit Bhagwat
Ranch Hand
Posts: 205
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hello friends

Thank you very much for your replies and time spent in answering my queries.

I am working on windows platform so folder cannot be renamed to a name that start with . (Dot .)

I want to hide from OS user. I mean I shouldnt be able to see that file/folder in windows if the option "Do not show hidden files/folders" is set in folders options.

Please help !!

Thanks and Regards
Rohit.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
As far as I know, Java doesn't provide a way to do that, as it's highly platform specific.
 
Sripathi Krishnamurthy
Ranch Hand
Posts: 232
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
File or folder cant be set to hidden from java. You have to use JNI (java native interface) to do so. I had one requirement to find the free space in a drive in windows machine and I used JNI to do so. This is another candidate for JNI.
 
Emmy Rauch
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
You don't need to use JNI to do this, you can just use STring cmd[] = {"attrib","+h",filename}; Runtime.getRuntime().exec(cmd); , (assuming you only want it to ever run on windows)
 
Rohit Bhagwat
Ranch Hand
Posts: 205
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hello Emmy

I will try your solution..

Thanks for the time spent in giving response..

Your solution seems interesting so I will try it out.

Till now I was trying to get help of JNI.. But I will be impressed if your solution works out..

Thanks sir and also Thanks to all those who have posted their response.

Regards
Rohit.
 
Rohit Bhagwat
Ranch Hand
Posts: 205
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hello Emmy Rauch

Thanks very much for your reply.

It did worked!!

Thanks and Regards
Rohit.
 
Sripathi Krishnamurthy
Ranch Hand
Posts: 232
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
Emmy,
Is there any similar way to get the free space from hard drive too?
Assuming that I will pass the drive letter to the function and it will return the total hard disc space & available hard disc space?

Thanks
 
Sripathi Krishnamurthy
Ranch Hand
Posts: 232
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
ok, never mind.
Sun has taken this as a priority. It will be available in "Mustang", java release in 2006. There will be methods to get the free space and total space.
http://bugs.sun.com/bugdatabase/view_bug.do;:YfiG?bug_id=4057701
 
Karthik Jayachandran
Ranch Hand
Posts: 91
Android AngularJS Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
i got this method working....

public void hideFileOrFolder(File file){

try{
Runtime.getRuntime().exec("attrib +a +s +h \""+file.getAbsolutePath().toString()+"\"");
}catch(Exception e){}

}


and to unhide a file or folder, just set "attrib -a -s -h"

 
Campbell Ritchie
Sheriff
Pie
Posts: 47274
52
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
Thank you, but after nearly 4 years the original poster may have given up waiting for an answer. Please read this dreadfully-named FAQ.
 
I agree. Here's the link: http://aspose.com/file-tools
    Bookmark Topic Watch Topic
  • New Topic