[python-win32] SHFileOperation doesn't work with UNICODE file paths (with non ascii characters)
shaileshk at gmail.com
Fri Aug 10 19:32:08 CEST 2007
Kindly have a look at following sample.
I am trying to copy files from a folder to another folder using SHFileOperation.
The folder name as well as file name contain characters from Hiragana
script (Japanese). Neither Copy nor Move operations work. The
operations work if the file path doesn't contain non-ascii characters.
What am I doing wrong?
I have PyWin32 - v 209.
from win32com.shell import shell, shellcon
def fileOperation(source, destination, operation):
result = shell.SHFileOperation((0, operation,
shellcon.FOF_NOERRORUI | shellcon.FOF_SILENT))
if result == 0:
raise Exception("Operation failed")
def copyFile(source, destination):
return fileOperation(source, destination, shellcon.FO_COPY)
def moveFile(source, destination):
return fileOperation(source, destination, shellcon.FO_MOVE)
if __name__ == '__main__':
"Lets do some testing of the above two functions"
testDir = ur"D:\\SHFOTestsDir"
"Some hiragana characters"
smallA = u'\u3042'
KA = u'\u304B'
GI = u'\u304E'
folder1Name = KA * 10
folder2Name = GI * 10
folder1Path = os.path.join(testDir, folder1Name)
folder2Path = os.path.join(testDir, folder2Name)
filenames = ()
contents = '20' * 100
for i in range(10):
filename = KA * (i + 5)
filepath = os.path.join(folder1Path, filename)
f = open(filepath, 'w')
More information about the python-win32