python - 如何从 ctypes 使用 IFileOperation

标签 python python-3.x winapi ctypes windows-shell

我想用IFileOperation从 python 代码复制文件 -

  • 它很快(比 python 快)
  • 你会得到一个很好的对话
  • 不阻塞 Python

  • 在 Windows 10 上,Python 3.8 -
    import ctypes
    
    ctypes.windll.shell32.IFileOperation
    

    似乎不存在。

    我如何联系 IFileOperation (不是已弃用的 SHFileOperation API)使用 ctypes ?

    最佳答案

    当然,它位于 pythoncomshell对于常量,例如:

    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/

    相关文章:

    python - Bokeh:链接线图和散点图

    python - 索引错误 : list index out of range python 3. 6

    Django-extension runscript 脚本没有(有效)模块

    python - 如何在 Django 中验证电话号码?

    c++ - 在 Windows 7 下编译的 Dll 在 Windows XP 下不起作用

    c# - 为什么 .NET 4 和 3.5 对 CloseHandle 异常的处理不同?

    python - 寻找在 python 中从 yelp review 数据集构建矩阵的有效方法

    python - 如何将 HTML 文件从我的 python 推送回网页

    python - 无法理解 os.walk 的目录导航

    c++ - C++:从程序,Windows和Linux中测量内存使用情况