我正在尝试编写一个 python 脚本,我可以使用 mobaxterm 从一个文件夹中抓取 25 个随机文件并将它们复制到另一个文件夹中。
我对使用 mobaxterm 非常陌生,我的实习主要是编写小脚本来帮助我的同事自动化日常工作,所以任何建议都值得赞赏!我可以打开 mobaxterm 并导航到保存此 python 脚本的文件夹,但出现以下错误:
IOError: [Errno 21] Is a directory:
我现在的代码如下
import shutil, random, os
dirpath = '/SSH_folder_where_stuff_is/images/'
destDirectory = '/SSH_folder_where_stuff_should_go/'
filenames = random.sample(os.listdir(dirpath), 25)
for fname in filenames:
srcpath = os.path.join(dirpath, fname)
shutil.copyfile(srcpath, destDirectory)
print('done!')
提前感谢您的任何建议!