私は Python の初心者ですが、すべてのダウンロードを並べ替えるプログラムを作成するのは楽しいと思いましたが、少し問題があります。目的地に単語が 1 つしかない場合は完全に機能しますが、目的地に単語が 2 つ以上ある場合は、ここで問題が発生し、プログラムがループに陥ります。リストを比較するのに私よりも優れたアイデアを持っている人はいますか
>>>for i in dstdir:
>>> print i.split()
['CALIFORNICATION']
['THAT', "'70S", 'SHOW']
['THE', 'BIG', 'BANG', 'THEORY']
['THE', 'OFFICE']
['DEXTER']
['SPAWN']
['SCRUBS']
['BETTER', 'OF', 'TED']
>>>for i in dstdir:
>>> print i.split()
['Brooklyn.Nine-Nine.S01E16.REAL.HDTV.x264-EXCELLENCE.mp4']
['Revolution', '2012', 'S02E12', 'HDTV', 'x264-LOL[ettv]']]
['Inequality', 'for', 'All', '(2013)', '[1080p]']
これはリスト出力の例です。
フォルダのみを含む宛先ディレクトリと、ダウンロード ディレクトリがあります。ソースファイル名を自動的に調べてから、宛先名を調べるプログラムを作成したいと思います。宛先名がソース名に含まれている場合は、ダウンロードしたファイルをコピーしてコレクションに並べ替えることができます。
destination = '/media/mediacenter/SAMSUNG/SERIES/'
source = '/home/mediacenter/Downloads/'
dstdir = os.listdir(destination)
srcdir = os.listdir(source)
for i in srcdir:
source = list(i.split())
for j in dstdir:
count = 0
succes = 0
destination = list(j.split())
if len(destination) == 1:
while (count < len(source)):
if destination[0].upper() == source[count].upper():
print 'succes ', destination, ' ', source
count = count + 1
elif len(destination) == 2:
while(count < len(source)):
if (destination[0].upper() == source[count].upper()):
succes = succes + 1
count = len(source)
count = 0
while(count < len(source)):
if (destination[1].upper() == source[count].upper()):
succes = succes + 1
count = len(source)
count = 0
if succes == 2:
print 'succes ', destination, ' ', source
今のところ、出力として「成功」だけで満足しています。近い将来、私にとってはまったく別の問題になるので、ファイルをコピーする方法を見つけます