Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copying files with native file manager in python

Okay, so I'm developing an application that will allow users to select file objects in a menu and will allow them to copy said selections to another location. I have so far managed to use the pywin32 module to allow me to copy files using Windows' native file copier.

The code for it:

from win32com.shell import shell, shellcon
srcstr = chr( 0 ).join( [ file[0] for file in files ] )
deststr = chr( 0 ).join( [ file[1] for file in files ] )
shell.SHFileOperation(
    ( 0, shellcon.FO_COPY, srcstr, deststr, shellcon.FOF_MULTIDESTFILES, None, None )
)

This is a fine method for copying under Windows, but I was wondering if there is a way to accomplish the same goal under Mac and/or Linux.

like image 758
halkion Avatar asked Mar 26 '26 02:03

halkion


1 Answers

Have you considered shutil (http://docs.python.org/library/shutil.html)? This module provides that sort of high-level file operations while remaining os-agnostic.

like image 77
andresuribe Avatar answered Mar 29 '26 02:03

andresuribe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!