0

以下のコードを実行した後、

import os, shutil, glob, sys
source_dir = sys.argv[1]

list = ['file1', 'fil2']
for seek in list:
        if seek == 'file1':
                dest_dir = '/root/my_dir'
        elif seek == 'file2':
                dest_dir = '/root/my_dir'
        paths = [(z, os.path.join(dest_dir, os.path.split(z)[1]))
                for z in glob.glob(os.path.join(source_dir, seek))]
        for p in paths:
                if os.path.isfile(p[1]):
                        new_path = p[1] + '.bak'
                        print ('File "{0}" already exists; 
                                moving to "{1}"'.format(p[1], new_path))
                        shutil.move(p[1], new_path)
                shutil.copy2(p[0], p[1])

次の例外が生成されます。

File "./config1.py", line 22, in <module>
  shutil.copy2(p[0], p[1])
File "/usr/local/lib/python3.0/shutil.py", line 99, in copy2
  copyfile(src, dst)
File "/usr/local/lib/python3.0/shutil.py", line 54, in copyfile
  copyfileobj(fsrc, fdst)
File "/usr/local/lib/python3.0/shutil.py", line 30, in copyfileobj
  fdst.write(buf)
File "/usr/local/lib/python3.0/io.py", line 1055, in write
  self._flush_unlocked()
File "/usr/local/lib/python3.0/io.py", line 1082, in _flush_unlocked
    n = self.raw.write(self._write_buf)
IOError: [Errno 28] No space left on device
4

1 に答える 1

2

あなたのドライブはいっぱいですか?

また、それらの行

    if seek == 'file1':
            dest_dir = '/root/my_dir'
    elif seek == 'file2':
            dest_dir = '/root/my_dir'

どちらの場合も dest_dir を同じ値に設定しています。

やるだけ

dest_dir = '/root/my_dir'
list = ['file1', 'fil2']
for seek in list:
    # your stuff

または、他の異なるケースを計画している場合は、

for seek in list:
    if seek in ('file1', 'fil2'):
        dest_dir = '/root/my_dir'
    elif seek in ('other_case', 'another_case'):
        dest_dir = '/foo'
于 2013-07-16T08:11:07.443 に答える