Hi,
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,
source, destination,
shellcon.FOF_NOCONFIRMATION |
shellcon.FOF_NOERRORUI | shellcon.FOF_SILENT))
if result == 0:
raise Exception("Operation failed")
return result
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"
import os
import sys
testDir = ur"D:\\SHFOTestsDir"
os.mkdir(testDir)
"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)
os.mkdir(folder1Path)
os.mkdir(folder2Path)
filenames = ()
contents = '20' * 100
for i in range(10):
filename = KA * (i + 5)
filepath = os.path.join(folder1Path, filename)
f = open(filepath, 'w')
f.write(contents)
f.close()
copyFile(filepath, folder2Path)
With regards,
- Shailesh
_______________________________________________
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32