pathnumbersironpythonrevitslash

Revit Ironpython Shell - Parsing a list of filenames with a number after a backslash in the path


I want to read in a list of files (inc path) from either a spreadsheet or a text file for some downstream processing. The list has been generated as a log from another process and the path includes a 2 digit year folder followed by a project number folder as follows:

\\servername\projects\19\1901001\project files\filetobeprocessed.abc

The problem is as soon as the above string is read in, it is interpreted as

\\servername\\projects\x019\x01901001\\project files\x0ciletobeprocessed.abc

Which then means that I cannot use the path to access the file.

Assigning the path string to a variable, I have tried:

thePath = repr(pathreadfromfile)

After assigning the path string I have tried fixing the string using

thePath.replace('\x0','\\')

thePath.replace('\\x0','\\')

thePath.replace(r'\x0','\\')

Nothing seems to fix the path so that it can be used to open the file. I can't find anything in either python or Ironpython that suggests a fix for this programatically. I know that you can fix this is the path is known within the code by using r'' to use raw text to create the path.

Any help appreciated


Solution

  • Obviously, the backslash \ is interpreted as an escape character.

    For a really simple solution, hopefully the simplest, I would suggest using forward slash / for all your path separators instead of backslash.

    If you really need the backslash somewhere further down the road, you can replace them back again.