/home/wiet/import/directory(再帰的)検索の下のフォルダから特定のファイル(* .txtで終わるファイル)を移動しようとしています。しかし、私は辞書に基づいてそれをやりたいと思っています - たとえば、フォルダ/ home/wiet/import/* OS.txtのファイルのみ、* rhel.txtは他のファイルについて移動する必要があります。ファイルと一致しないことについて(できればそれらをいくつかのリストに追加する)。今の私は、以下のこの1を持っているが、私は辞書でそれを一致させることはできないと私は私が何をしたいかわからない別のディレクトリPythonは辞書に基づいてファイルを移動します
import sys
import os
import shutil
import glob
import fnmatch
tech = {"OS": ["rhel.txt", "windows.txt"]
"DB" : ["mysql.txt","oracle.txt","postgres.txt","postgresql.txt"],
"WEB" : ["iis.txt" , "apache.txt", "tomcat.txt" ] ,
}
fileslist = []
txtcorrect = []
destin = "/home/wiet/import"
print "part1 \n \n \n"
path = os.path.join(destin)
for path, subdirs, files in os.walk(destin):
for name in files:
if name.endswith('.txt'):
print "found: " + name
for root, dirnames, filenames in os.walk(path):
for filename in fnmatch.filter(filenames, '*.txt'):
txtcorrect.replace(os.path.join(root, filename))
print txtcorrect
shutil.copy2(txtcorrect , '/home/wiet/out')
'徒歩()' '徒歩()'私には少し奇妙に思えるの内側、外側の散歩は、すでにすべてのディレクトリを訪問していませんか? –
良い点ですが、辞書キーとその値とのパスを一致させる方法を探しています – wiet
エラーメッセージ/観察結果は何ですか? 'copy2()'の最後の行は疑わしく見え、 'txtcorrect'はまだリストです。 –