• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to check whether name of the File is in a Specifi format??

 
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am expecting the Filename to be in a specified format that is "Test_INT.NO1.<dd><MM><yy><HH><mm><ss>.txt"

for example

"Test_INT.NO1. 28 06 10 12 25 56.txt"

But Please let me know how do i check the File name has got a specific format or not ??

Please share your ideas on this .

Thanks in advance .
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use a regular expression?
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I like Paul's answer.
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Filenames retrieved will be in the form of String. In my opinion, identifying the time format accurately is not always possible.

The only way I see is, to validate every parameter for its limits. such as 31 for <dd>, 12 for <MM> etc. This validation technique could help you to identify some parameters and factor the rest.
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd prefer to use a DateFormat to check if the date is valid, rather than manually checking bounds. Using a DateFormat and its parse(String, ParsePosition) method you can even prevent any ParseExceptions:
That parse method returns null if the input is invalid. The other check also makes sure that the parsing consumes the entire input; parse methods usually allow trailing data; for instance, with "Test_INT.NO1. 28 06 10 12 25 56.txtabc" as input, the parse position's index will point at the a, allowing you to parse some more. Since we don't want to parse more or allow this trailing data the check ensures that the format will consume the entire text.
reply
    Bookmark Topic Watch Topic
  • New Topic