aspose file tools*
The moose likes Java in General and the fly likes URGENT :- Hide folder / file using Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic
Author

URGENT :- Hide folder / file using Java

Rohit Bhagwat
Ranch Hand

Joined: Dec 19, 2004
Posts: 205
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

Joined: Dec 13, 2002
Posts: 79
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

Joined: Mar 22, 2000
Posts: 12825
    
    5
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

Joined: Jul 11, 2001
Posts: 14112
http://faq.javaranch.com/view?HowToAskQuestionsTheSmartWay


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Rohit Bhagwat
Ranch Hand

Joined: Dec 19, 2004
Posts: 205
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

Joined: Jul 11, 2001
Posts: 14112
As far as I know, Java doesn't provide a way to do that, as it's highly platform specific.
Sripathi Krishnamurthy
Ranch Hand

Joined: Mar 07, 2005
Posts: 232
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

Joined: Jul 07, 2004
Posts: 12
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

Joined: Dec 19, 2004
Posts: 205
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

Joined: Dec 19, 2004
Posts: 205
Hello Emmy Rauch

Thanks very much for your reply.

It did worked!!

Thanks and Regards
Rohit.
Sripathi Krishnamurthy
Ranch Hand

Joined: Mar 07, 2005
Posts: 232
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

Joined: Mar 07, 2005
Posts: 232
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

Joined: Feb 18, 2009
Posts: 88

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

Joined: Oct 13, 2005
Posts: 39885
    
  28
Thank you, but after nearly 4 years the original poster may have given up waiting for an answer. Please read this dreadfully-named FAQ.
 
 
subject: URGENT :- Hide folder / file using Java