![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi Everyone, I was just rummaging around and came across a startling fact (for me anyway). I have no routine to parse a windows or unc path and filename to see if it is well formed or not. I had a bit if a dig around on teh net and mainly found debtes on what is valid and what isnt, complete with loads of non-functional regular expressions. I have two questions: 1/ Is it that hard to actually parse a windows file / path or unc path for 'well formedness' 2/ Is there an accepted method of doing this parsing? Can anyone point me in the right direction here? It is not an urgent thing but something I will need to take care of in the next week or two. If anybody has any data on this or sample code I would greatly appreciate the pointers (or even a complete module!) Cheers The Frog |
#3
| |||
| |||
|
|
"The Frog" <mr.frog.to.you (AT) googlemail (DOT) com> wrote in message news:b7b19001-5e51-490b-a4c8-38f43969f901 (AT) 35g2000yqm (DOT) googlegroups.com... Hi Everyone, I was just rummaging around and came across a startling fact (for me anyway). I have no routine to parse a windows or unc path and filename to see if it is well formed or not. I had a bit if a dig around on teh net and mainly found debtes on what is valid and what isnt, complete with loads of non-functional regular expressions. I have two questions: 1/ Is it that hard to actually parse a windows file / path or unc path for 'well formedness' 2/ Is there an accepted method of doing this parsing? Can anyone point me in the right direction here? It is not an urgent thing but something I will need to take care of in the next week or two. If anybody has any data on this or sample code I would greatly appreciate the pointers (or even a complete module!) Cheers The Frog Here's what I use. It covers all of the mistakes in paths that I've ever seen: Public Function IsLegalFileName(ByVal s As String, Optional FullPath As Boolean) As Boolean Const Illegals = "<>\/:?|*" & """" Dim sl As Long, i As Long ' sl = Len(s) If sl = 0 Or sl > 260 Then Exit Function If FullPath Then Select Case Mid$(s, 2, 1) Case ":", "\" 'do nothing Case Else Exit Function End Select End If For i = 1 To sl If InStr(1, Illegals, Mid$(s, i, 1)) Then Exit Function End If Next IsLegalFileName = True End Function I'm sure someone could make the task far more complicated, but as I say this covers everything I've come across (for years). Hope it helps. |
#4
| |||
| |||
|
|
Hi Everyone, I was just rummaging around and came across a startling fact (for me anyway). I have no routine to parse a windows or unc path and filename to see if it is well formed or not. I had a bit if a dig around on teh net and mainly found debtes on what is valid and what isnt, complete with loads of non-functional regular expressions. I have two questions: 1/ Is it that hard to actually parse a windows file / path or unc path for 'well formedness' 2/ Is there an accepted method of doing this parsing? Can anyone point me in the right direction here? It is not an urgent thing but something I will need to take care of in the next week or two. If anybody has any data on this or sample code I would greatly appreciate the pointers (or even a complete module!) |
#5
| |||
| |||
|
#6
| |||
| |||
|
|
Thanks to both of you for your knowledge sharing. I deeply appreciate it. I was growing increasingly concerned that I would need to create some 'super parser' to be able to deal with the issue having not realised how convoluted the problem really is. These are both simple and direct tools I can use. Thankyou Cheers The Frog |
#7
| |||
| |||
|
#8
| |||
| |||
|
|
Thanks once again. The Frog |
#9
| |||
| |||
|
|
You can use very usefull dll: shlwapi |
#10
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |