• Post Reply Bookmark Topic Watch Topic
  • New Topic

Regex for file path  RSS feed

 
vivek dhiman
Ranch Hand
Posts: 155
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have the String which i need to validate that valid files are there or not. Like "/path/to/file1,/path/to/file2,path/to/file3". What can be the regex to validate such path with comma separated file list.

Thanks
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you insist it be done with a regex?
 
vivek dhiman
Ranch Hand
Posts: 155
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am trying to place some validation on the file path, so thats why looking towards regex, if any other alternative is there please advice.
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vivek dhiman wrote:Hi, I am trying to place some validation on the file path, so thats why looking towards regex, if any other alternative is there please advice.

If you are using Java 1.7 take a look at java.nio.file.Path. In Java 1.6 or earlier you should find appropriate method in java.io.File.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems to me that it would be simpler to use something like the String.split() method to break it apart on the comma character, then iterate through the list to validate what's in it.
 
vivek dhiman
Ranch Hand
Posts: 155
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reply. Below is my code that i am using for path validation.

Not actually getting to validate path of individual file.Please suggest. Requirement for regex (for file path )is something like /StringorNum/StringorNum/StringorNum...... So on such pattern can be 1-M.
 
Paul Clapham
Sheriff
Posts: 22835
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exactly do you want to check? That a file path in the list is a well-formed file path, or that it corresponds to an actual file on your file system?
 
Amit Ghorpade
Bartender
Posts: 2856
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it is a good idea to try open the file without validating the path. A valid path string may not represent a valid file, it will fail anyhow.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!