Results 1 to 6 of 6
-
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; }
- 03-28-2011, 12:24 PM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
What happen when you execute the command manually on command prompt, is it work?
-
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.
-
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.
-
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.
-
Similar Threads
-
How to make EXE from code?
By heyitsmebenjamin in forum New To JavaReplies: 1Last Post: 01-09-2011, 06:37 PM -
how to make my code better
By vendetta in forum New To JavaReplies: 4Last Post: 02-10-2010, 09:14 PM -
need to adjust a code I have to work with hidden fields
By carag in forum New To JavaReplies: 2Last Post: 07-29-2009, 12:23 PM -
How to create directory through Java Code
By Java Tip in forum java.ioReplies: 1Last Post: 04-14-2009, 03:34 PM -
How to make delete particular extension file from a directory
By Java Tip in forum java.ioReplies: 0Last Post: 04-05-2008, 10:13 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks