0

I am trying to match a specific word in between backslashes in the windows file path of a file. The value to match is "Psb+" for this case

X:\Guli\Proc(Loops)\Read\Psb+\İngil\Fate\5.0X[Lxss.] [Psb+] Instructions.txt

Due to software limitations I cannot use import os but I can use Pythonnet.

My regex is like this

pFilePath = "X:\Guli\Proc\(Loops)\Read\Psb+\İngil\Fate\5.0X\[Lxss.] [Psb+] Instructions.txt"
searchtext = "Psb+"    
pm = re.search(r'(?i)(?<="\\")' + searchtext + r'(?="\\")', pFilePath)

It runs OK in the Visual Studio Core but when I try it on my environment, I get this error:

parsing ............. - Too many )'s.

I am stuck with this. Is there a more clever way of doing this?

Lax
  • 21
  • 5
  • You have to escape the backslashes in `pFilePath`. – Toto Aug 13 '20 at 16:30
  • Is there any way to automatically convert the pFilePath instead of manually escaping every illegal character? I cannot import os. – Lax Aug 13 '20 at 16:36
  • https://stackoverflow.com/q/24769242/372239 https://stackoverflow.com/q/54713670/372239 – Toto Aug 13 '20 at 16:40
  • pFilePath.replace(r"\" , r"\\") this gives error and doesn't work SyntaxError: unexpected character after line continuation character – Lax Aug 13 '20 at 17:03

1 Answers1

0

After trying a lot of things,

I got around the issue by implementing Directory.GetDirectories Method using IronPython.

import clr
from System.IO import Path, File, Directory

https://learn.microsoft.com/en-us/dotnet/api/system.io.directory.getdirectories?view=netcore-3.1

Then I found a way to import os by using symbolic links.

Lax
  • 21
  • 5