List Info

Thread: Getting the file name and the path into separate variables from the absolute path




Getting the file name and the path into separate variables from the absolute path
user name
2006-01-15 18:13:38
flavor .NET

pattern

(c:[wx20\]+\)([w]+.jpg)

will match yr sample input
c:documents and settingsblahblah2picture.jpg

and store the result in 2 groups:

1st one:  c:documents and settingsblahblah2
2nd one: picture.jpg

later in the supporting code u need to access the groups and
store the
contents of them in the vars (strings)

note that w will match [a-zA-Z0-9_] only.

Getting the file name and the path into separate variables from the absolute path
user name
2006-01-18 14:43:59
flavor  TCL (although not needed there)

i think relying on a specific characterset for filenames
might not be a
good idea. I think this pattern is preferable

(.*\)([^\]*).

Note: Works only with a "greedy" regex
implementation and no check is
covered whether the full searchstring was matched.

Getting the file name and the path into separate variables from the absolute path
user name
2006-01-18 18:36:18

Torsten , did u mean

(.*\)([^\]*)

or even

(.*\)([^\]+)      #otherwise it'll give u an empty match
at the end
w/smth like 'c:'

i.e w/o the dot at the end?Thne yes it works fine. Good
thinking.
Thnaks for this one.

Sergei

Getting the file name and the path into separate variables from the absolute path
user name
2006-01-20 14:23:32
Hi Sergei,

you are right, Originally the dot was meant to be "full
stop - end of
sentence".

"*" or "+" actually depends whether the
OP could have data ending with
a ""

Regards Torsten

[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )