1

Python newbie. Need some help with a simple file copy app/script.

Ask user to select files (may include directories) and then copy all selected to a destination directory recursively (create sub-directories if required. .

I am able to select and copy only files using the code below' (sample code snippet)

Not sure how to select both files and directories in a go and start copy.

import tkinter.filedialog as fd
import os
import shutil

files=fd.askopenfilenames()     # user selects files
for item in files:
    shutil.copy(item, dest_path)   # destination path is predefined. say C:/testdir/
Vjsh
  • 11
  • 3
  • You cannot select both files and directories with tkinter filedialogs. There is one for directories, `askdirectory` and the one you used for files. If you want to do both, you will have to code your own dialog. – j_4321 Aug 06 '19 at 10:49
  • A similar question (https://stackoverflow.com/questions/36224235/how-can-i-use-the-same-dialog-box-in-tkinter-to-browse-and-select-files-and-dire) was asked before and the answers confirm my previous comment, there is no easy solution. – j_4321 Aug 06 '19 at 10:53
  • I am the developer of the [tkfilebrowser](https://pypi.org/project/tkfilebrowser/) module which offers alternatives to the standard tkinter filedialogs for Linux and Windows. You gave me the idea to add an option to select both files and directories, which is rather quick to do. You can try the [development branch](https://github.com/j4321/tkFileBrowser/tree/dev) if you want. The `askopenpathnames()` function should do what you want. – j_4321 Aug 06 '19 at 12:15

0 Answers0