私はコンピュータのリストを通過すると.exe.configファイルのコピーと同じ構造
Iのファイル拡張子とは何のためにある特定のディレクトリとサブディレクトリを探していますの新しいサブディレクトリに配置します.exe.configで終わるファイルを取り出し、同じ構造のバックアップディレクトリに置いてください。これは再帰的に行われます。
たとえば、「main」はメインディレクトリです。などの番号のディレクトリのそれぞれにおいて
main
\
\-----------
\ \ \
1 2 3
を、「1」、「2」、「3」と呼ばれる「メイン」内のいくつかのサブディレクトリがありますが、.exe.config
の拡張子を持つファイルが存在することになりますメインディレクトリ名、サブディレクトリ名、* .exe.configファイルを取得します。次に、同じ構造のバックアップ "メイン"ディレクトリに配置します。
これらの番号が付いたディレクトリには他のファイルがありますが、それらのファイルは無視します。
すべてを再帰的にコピーできません。ここで私がテストしているコードです。コンピュータの一覧はserverlist.txtに格納されます
import os
import shutil
import fileinput
def copy_names(servername):
source = r'//' + servername + '/c$/Program Files (x86)/Main/'
dest = r'//' + servername + '/c$/' + servername + '/Main/'
for root, dirs, files in os.walk(source):
for file in files:
if file.endswith('.exe.config'):
try:
os.makedirs(dest, exist_ok=True)
shutil.copyfile(os.path.join(source, file), os.path.join(dest, file))
print ("\n" + servername + " " + file + " : Copy Complete")
except:
print (" Directory you are copying to does not exist.")
def start():
os.system('cls' if os.name == 'nt' else 'clear')
array = []
with open("serverlist.txt", "r") as f:
for servername in f:
copy_names(servername.strip())
# start program
start()