The path is passed to the function of the form D: \ folder \ file.txt. The problem is that the os.path.dirname (src) function works correctly only with double slash \ or single backslash paths.
It seems that you just need to make a replacement, but my replacement leads to some kind of abcadabra src path = D: /ProjectB4rchdata♀older1.ini
I can not understand where these special characters come from. Can the os.path.dirname function work incorrectly?
Here is the code itself
# -*- coding: utf8 -*- import os import ntpath import shutil dst_sav = "D:\\savorsk\\" #.replace("\\","/") def copyfilestofolder(src): src = src.replace("\\","/") print "src path = %s" %src dbfilepath = os.path.dirname(src) print dbfilepath copyfilestofolder("D:\Project\2014\archdata\folder1.ini")
I just need to somehow get into the dbfilepath variable the path to the directory in which the file lies, but nothing happens.
Tell me the solution.