Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

URGENT :- Hide folder / file using Java

 
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
http://faq.javaranch.com/view?HowToAskQuestionsTheSmartWay
 
Rohit Bhagwat
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
As far as I know, Java doesn't provide a way to do that, as it's highly platform specific.
 
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 93
Python Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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"

 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
    Bookmark Topic Watch Topic
  • New Topic