# -*- coding: iso-8859-1 -*- #. // _by_FileToUrl.py #. // Convertir un nom de fichier Windows en URL. from os import getcwd def by_FileToUrl( cFile ): if cFile.find( "/" ) > -1: # // Url : ne pas convertir. return cFile #. endif cReturn = cFile cDirWork = getcwd() if cReturn.find( "\\" ) == -1: # // fichier sans son dossier, on le rajoute. cReturn = cDirWork + "\\" + cReturn elif cReturn[ : 1 ] == "\\": cReturn = cDirWork[ : 2 ] + cReturn #. endif cReturn = "file:///" + cReturn.replace( "\\", "/" ) return cReturn ''' Dernière modification : 2022-02-20 [Exemple] import sys sys.path.append( "modules" ) from _by_FileToUrl import by_FileToUrl # // Convertir un nom de fichier Windows en URL. print() print( by_FileToUrl( "c:\\Test\\Python\\Test.txt" ) ) print( by_FileToUrl( "\\Test\\Python\\Test.txt" ) ) print( by_FileToUrl( "Test.txt" ) ) print( by_FileToUrl( "file:///C:/BpPy/_Lib/by_Tests/_by_FileToUrl/Test.txt" ) ) print( by_FileToUrl( "https://google.fr" ) ) [/Exemple] '''