1

I am working on an application installer. The user has to provide a file / directory path that will later be created by the application. I need to check if that path is valid (could exists). The problem is that I can not call file.exists() because it might not exist.

I know I could try to create it and then delete it. If it fails, the path is not valid. But is there a better, simpler way? Also, my work around requires special permissions for my installer which is not very good.

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
sebi
  • 21
  • 2

1 Answers1

0

Depends on your criteria for a valid path.

  • If you mean: path is well formed: Use regular expressions
  • If you mean: path is available, try !file.exists();

A regular expression for Unix based systems could be like this: [^\0]+

Also,you'll find lots more information in this SO Question

Community
  • 1
  • 1
Bart Vangeneugden
  • 3,436
  • 4
  • 33
  • 52
  • I mean well formed, but i would resort to regular expressions as a last resort - for a pattern such as a valid path in windows they get big and error prone. – sebi May 18 '11 at 09:20