我很难将 mp4 文件从一个目录移动到另一个目录(Ubuntu Linux)。当我在目录之间移动 .py 文件时,我随附的代码似乎可以完美运行。我在谷歌上做了一些研究以寻找答案,但无济于事。我找到了指向权限等的答案,并且我从以下 url 中找到了帮助。
http://stackoverflow.com/questions/13193015/shutil-move-ioerror-errno-2-when-in-loop
http://stackoverflow.com/questions/7432197/python-recursive-find-files-and-move-to-one-destination-directory
我是python新手,刚刚学习。请您帮忙处理我包含的代码以及我在运行 python 脚本移动 .mp4 文件时收到的错误消息。
sudo python defmove.py /home/iain/dwhelper /home/iain/newfolder .mp4
(我从 defmove.py 脚本所在的目录运行脚本,并且在运行 defmove.py 之前我还确保 newfolder 不存在)
import os
import sys
import shutil
def movefiles(src,dest,ext):
if not os.path.isdir(dest):
os.mkdir(dest)
for root,dirs,files in os.walk(src):
for f in files:
if f.endswith(ext):
shutil.move(f,dest)
def main():
if len(sys.argv) != 4:
print 'incorrect number of paramaters'
sys.exit(1)
else:
src = sys.argv[1]
dest = sys.argv[2]
ext = sys.argv[3]
movefiles(src,dest,ext)
主要的()
Traceback (most recent call last):
File "defmove.py", line 24, in <modeule>
main()
File "defmove.py", line 22, in main
movefiles(src,dest,ext)
File "defmove.py", line 11, in movefiles
shutil.move(f,dest)
File "/usr/lib/python2.7/shutil.py", line 301, in move
copy2(src, real_dst)
File "/usr/lib/python2.7/shutil.py", line 130, in copy2
copyfile(src,dest)
File "/usr/lib/python2.7/shutil.py", line 82, in copyfile
with open(src, 'rb') as fsrc:
IOError: [Errno 2] No suck file or directory: 'feelslike.mp4'