Py学习  »  Python

如何用python将多个文件名称中的空格移动?

Ger Cas • 4 年前 • 501 次点击  

我要从目录中移动多个文件(仅文件而不是文件夹) source 到目录 dest . 我在下面用 for 循环:

import os
import shutil
import glob

source = "r'" + "/This is/the source path/"
dest = "r'" + "/This is/the destination path/"

files = glob.glob(source+'/*.*')    

for f in files:
    shutil.move(source+f, dest)

>> IOError: [Errno 2] No such file or directory:

但是如果我为这样的一个文件做,它是有效的。

source = "/This is/the source path/"
dest = "/This is/the destination path/"

file_1 = r'This is a file.txt'
shutil.move(source+file_1, dest) ## This works

我怎样才能点几个文件?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/39473
 
501 次点击  
文章 [ 1 ]  |  最新文章 4 年前