aspose file tools
The moose likes I/O and Streams and the fly likes creating hidded file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Groovy Fundamentals video training course this week in the Groovy forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "creating hidded file" Watch "creating hidded file" New topic
Author

creating hidded file

Rob Qas
Ranch Hand

Joined: Apr 10, 2006
Posts: 34
dear all..

want to create hidden files , Can anyone provide some sample code for doing this.
thanks..
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24189
    
  34

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.


[Jess in Action][AskingGoodQuestions]
Paul Clapham
Sheriff

Joined: Oct 14, 2005
Posts: 19553
    
  10

The Windows command to make files "hidden" is the ATTRIB command. Any Windows file can be made hidden or not hidden.
tariq shadid
Greenhorn

Joined: Jul 31, 2006
Posts: 11
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

Joined: Jul 31, 2006
Posts: 11
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

Joined: Jul 08, 2003
Posts: 24189
    
  34

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?
 
Consider Paul's rocket mass heater.
 
subject: creating hidded file