I'm trying to simply move files from folder path1 to folder path.
import os
import shutil
path1 = '/home/user/Downloads'
file_dir = os.listdir(path1)
fpath = '/home/user/music'
for file in file_dir:
if file.endswith('.mp3'):
shutil.move(os.path.join(file_dir,file), os.path.join(fpath, file))
... but I get this error
TypeError: expected str, bytes or os.PathLike object, not list
listdir()returns a list containing the names of the entries in the directory given by path. source. Dofile_dir = os.listdir(path1)[0]perhaps?(os.path.join(file_dir,file)here you are trying to join a list with a string, check this line again.(os.path.join(file_dir,file)should be(os.path.join(path1,file)I believe.