-1

I want to create a folder that starts with . character. I tried File(path).mkdir() but does not work. I cannot create from "right click->new folder". Windows blocks creating folders starting with dot character. From command prompt I can easily create via mkdir [folder_name]. Do I have any mistakes here. If not how can I execute this command in java or any other suggestion will be helpful?

Note: Process p = Runtime.getRuntime().exec("mkdir .test"); //Does not work

Note2: My code will be platform dependent.

assylias
  • 321,522
  • 82
  • 660
  • 783
user
  • 43
  • 5
  • 3
    What did actually not work with File(path).mkdir()? How does your code look like? Using the Runtime approach does not work since mkdir is builtin to the command shell on windows. You need to call "cmd.exe" with appropriate parameters – Andreas Fester Oct 30 '12 at 14:52
  • 1
    Hope those 2 help: http://stackoverflow.com/q/1999437/1007273 & http://stackoverflow.com/q/1294989/1007273 – hovanessyan Oct 30 '12 at 14:52

2 Answers2

1
new File("C:\\Temp\\.folder").mkdir();

Works for me. Note that mkdir() returns a boolean which indicates success or failure. It can fail if you have no permission to create the folder, for example.

(Note: When you ask a question, explain what "does not work" means.)

Jesper
  • 202,709
  • 46
  • 318
  • 350
0

Platform independant OS functions are not so simple in java but you could wrap it around an ant mkdir task that would be platform independant. The usage is slightly roundabout but is/could be quite powerful

Community
  • 1
  • 1
sfk
  • 625
  • 1
  • 9
  • 17