我想用IFileOperation从 python 代码复制文件 -
在 Windows 10 上,Python 3.8 -
import ctypes
ctypes.windll.shell32.IFileOperation
似乎不存在。
我如何联系
IFileOperation
(不是已弃用的 SHFileOperation
API)使用 ctypes
?
最佳答案
当然,它位于 pythoncom和 shell
对于常量,例如:
from win32com.shell import shell
import pythoncom
# create an instance of IFileOperation
fo = pythoncom.CoCreateInstance(shell.CLSID_FileOperation, None, pythoncom.CLSCTX_ALL, shell.IID_IFileOperation)
# here you can use SetOperationFlags, progress Sinks, etc.
# create an instance of IShellItem for the source item
item1 = shell.SHCreateItemFromParsingName("c:\\temp\\source.txt", None, shell.IID_IShellItem)
# create an instance of IShellItem for the target folder
folder = shell.SHCreateItemFromParsingName("c:\\another", None, shell.IID_IShellItem)
# queue the copy operation
fo.CopyItem(item1, folder, "new name.txt", None)
# commit
fo.PerformOperations()
关于python - 如何从 ctypes 使用 IFileOperation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62065891/