Первая функция следующей программы работает хорошо, но
не знает, как вызвать первую функцию во второй функции и скопировать ее результаты в новый каталог.
Как распечатать найденные файлы в первой функции в разных строках? (каждый файл в одной строке)
Спасибо.
# Write a program that walks through a folder tree and searches for files with
# a certain file extension (such as .pdf or .jpg). Copy these files from whatever
# location they are in to a new folder.
import os, shutil, fnmatch
def find_all(pattern, path):
result = []
for root, dirs, files in os.walk(path):
for name in files:
if fnmatch.fnmatch(name, pattern):
result.append(os.path.join(root, name))
return result
print(find_all('*.jpg', 'D:\\firstfolder'))
# Copy the found files into another directory
def found_files(dst):
dst = os.chdir('D:\\secondfolder')
for files in find_all():
shutil.copytree(dst)
found_files(dst)