I am trying to take a file and put it into all directories 1 level down.
JavaScript
x
2
1
TypeError: stat: path should be string, bytes, os.PathLike or integer, not tuple
2
JavaScript
1
15
15
1
import shutil
2
import tkinter as tk
3
from tkinter import filedialog
4
import os
5
6
root = tk.Tk()
7
root.withdraw()
8
9
files = filedialog.askopenfilenames(parent=root, title='Choose file/s')
10
path = filedialog.askdirectory()
11
12
for dirs in path:
13
shutil.copy(files, dirs)
14
15
I thought that this would be simple, what am I doing wrong?
Advertisement
Answer
Since it is “askopenfilenames
“, it returns the results in the form of a tuple. You can iterate over it and move the files to the directory selected:
JavaScript
1
15
15
1
import shutil
2
import tkinter as tk
3
from tkinter import filedialog
4
import os
5
6
root = tk.Tk()
7
root.withdraw()
8
9
files = filedialog.askopenfilenames(parent=root, title='Choose file/s')
10
j=filedialog.askdirectory()
11
path = [os.path.join(j,i) for i in os.listdir(j) if os.path.isdir(os.path.join(j,i))]
12
13
for fols,dirs in zip(path,files):
14
shutil.copy(dirs, fols)
15