in reply to Re: finding the path of the script running as Win service
in thread finding the path of the script running as Win service

thanks for the explanation re compile and run times. Now, if someone to be kind enough to explain what is Boris doing in the above regex... I don't like magic.

;-)

  • Comment on Re^2: finding the path of the script running as Win service

Replies are listed 'Best First'.
Re^3: finding the path of the script running as Win service
by jdalbec (Deacon) on Jan 06, 2005 at 02:08 UTC

    The regex matches a backslash (\\) followed by any number of non-backslash characters ([^\\]*) followed by end-of-string ($). This forces the matched backslash to be the last backslash in the string, so the matched non-backslash characters are the filename ("foo.exe"). The matched characters ("\foo.exe") are replaced by the empty string, which gives the directory containing the script file ("E:\programs\foo").

    The OP accomplished this less efficiently by splitting the string on backslashes (("E:","programs","foo","foo.exe")), popping the last element of the array ("foo.exe", leaving ("E:","programs","foo")), and rejoining the array with backslashes ("E:\programs\foo").