Results 1 to 6 of 6
  1. #1
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default Why doesn't this code make the directory hidden?

    Java Code:
        public static String createDirectory(String subdirectory) {
            String finalDirectory = SAVE_DIRECTORY + subdirectory;
            try {
                boolean success = (new File(finalDirectory).mkdirs());
                if (success) {
                    String cmd="attrib +h "+finalDirectory;
                    Runtime.getRuntime().exec(cmd);
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            return finalDirectory;
        }

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  3. #3
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    Nope, no errors - program runs as normal. Directory is created and files saved to it. If directory is already there, no problems either, files saved to it. Only problem is the directory needs to be hidden but it isn't hiding. I learnt that this is the correct code for Windows but i don't know if it is compatible with windows 7 (64bit) which i am running. Once i hide successfully i will also lock the directory somehow.

  4. #4
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    further info:
    ------------
    just in case it was a problem with the condition, i took out the condition (if(successful)).

    same thing.

    i was saving it to a logical drive (N:/) but now i've change the directory to C:/ and i have the same problem.

  5. #5
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    okay i found the problem:

    my createDirectory() method was returning a directory name with "/" at the end, so the command was returning

    attrib +h dir1/dir2/

    which when i tried to type in CMD gave the error that File doesn't exist, so i took out the last "/" and it works now.

  6. #6
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    this was my final solution:

    Java Code:
                String cmd="attrib +h +s "+SAVE_DIRECTORY.concat("*") + " /S /D";
                Runtime.getRuntime().exec(cmd);

Similar Threads

  1. How to make EXE from code?
    By heyitsmebenjamin in forum New To Java
    Replies: 1
    Last Post: 01-09-2011, 07:37 PM
  2. how to make my code better
    By vendetta in forum New To Java
    Replies: 4
    Last Post: 02-10-2010, 10:14 PM
  3. Replies: 2
    Last Post: 07-29-2009, 01:23 PM
  4. How to create directory through Java Code
    By Java Tip in forum java.io
    Replies: 1
    Last Post: 04-14-2009, 04:34 PM
  5. Replies: 0
    Last Post: 04-05-2008, 11:13 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •