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

creating hidded file

 
Rob Qas
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dear all..

want to create hidden files , Can anyone provide some sample code for doing this.
thanks..
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is an OS-dependent thing; there's no Java API for it. On UNIX, by convention, hidden files are those whose names start with a dot (.). Does Windows have hidden files? If so, if it's name-based, then just use the appropriate names; otherwise, perhaps you can run some Windows command using Runtime.exec() to make files into hidden files.
 
Paul Clapham
Sheriff
Pie
Posts: 20190
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Windows command to make files "hidden" is the ATTRIB command. Any Windows file can be made hidden or not hidden.
 
tariq shadid
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes you can use windows command to create hidden folder which is "ATTRIB +h"
and here sample code


import java.io.*;
public class Class1
{
public static void main( String[] argv )
{

String folderName = "\\whatevere";
File fp = new File(folderName);
fp.mkdir();

String command = "ATTRIB +h \\"+folderName;

try
{
Process process = Runtime.getRuntime().exec("cmd /C "+command );
process.waitFor();
System.out.println("Exit code is " + process.exitValue());
}
catch ( Exception ioex )
{
ioex.printStackTrace();
}
}
}
 
tariq shadid
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and i write this code in unix to create hidden folder which is:

boolean setHidden(boolean value)
{
if (value && !isHidden())
return renameTo('.' + getPath());
else if (isHidden())
return renameTo(getPath().substring(1));
else
return false;
}

but it doesnt work

can any body help me

Tariq Shadid
PHP DEVELOPER
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by tariq shadid:

but it doesnt work


Doesn't work in the sense that it doesn't compile, or given appropriate utility methods to make it compile, it doesn't do the right thing?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic