Acording to @ArgiriKotsaris note, you can use os.path.normpath(path):
Normalize a pathname by collapsing redundant separators and up-level references.
So that A//B, A/B/, A/./B and A/foo/../B all become A/B.
This string manipulation may change the meaning of a path that contains symbolic links.
On Windows, it converts forward slashes to backward slashes.
So your code be:
import maya.cmds as cmds
import os
path = cmds.fileDialog2(fm=3,dialogStyle =1)
path = path and os.path.normpath(path[0])
Or if you want to always using forward slashes, then no needs to os module and change last line to:
path = path and path[0].replace('\\', '/')
Note that name of file mode argument for fileDialog2 is fileMode or fm and not filemode.
Also fileDialog2 return a list of paths or None.
os.path.normpath(filePath)has worked for me so far... - Argiri Kotsarisout.replace('\\', '/')- Saullo G. P. Castro