代码想复制文件夹下的 .md 文件到另一个文件夹中
import os
def copy_file ( dirname ):
"""Copy .md file in a given directory and its subdirectories.
"""
for root, dirs, file in os.walk ( dirname ):
for f in file:
if os.path.splitext (root+f )[1] == ".md":
os.system ("cp %s ~/file/"%os.path.join ( root, f ))
copy_file ('.')
可是因为文件名带空格,报这样的错误,请问有什么好的处理方法呢?
cp: cannot stat ‘./Chapter ’: No such file or directory
cp: cannot stat ‘ 01 ’: No such file or directory
cp: cannot stat ‘ Best ’: No such file or directory
cp: cannot stat ‘ Friends/from-morse-to-binary.md ’: No such file or directory
cp: cannot stat ‘./Chapter ’: No such file or directory
cp: cannot stat ‘ 02 ’: No such file or directory
cp: cannot stat ‘ Code ’: No such file or directory