0
Python言語を使用して、指定したFileShareの場所からファイル名の一覧を取得します(唯一)。ここに私のコードスニペットがありますが、それはすべてのファイルのリストを実行していません。Pythonがアクセスし、ユーザー名とパスワードでネットワーク共有のファイルを一覧表示します。
import os
from os import walk
SQLSR_USER= 'username'
SQLSR_PASS= 'password'
BACKUP_REPOSITORY_PATH= '\\fileshare\location'
fileList = []
backup_storage_available = os.path.isdir(BACKUP_REPOSITORY_PATH)
if backup_storage_available:
print("Backup storage already connected.")
else:
print("Connecting to backup storage.")
mount_command = "net use /user:" + SQLSR_USER + " " + BACKUP_REPOSITORY_PATH + " " + SQLSR_PASS
os.system(mount_command)
backup_storage_available = os.path.isdir(BACKUP_REPOSITORY_PATH)
if backup_storage_available:
print ("Connection success.")
else:
raise Exception("Failed to find storage directory.")
for (dirpath, dirnames, filenames) in walk(backup_storage_available):
fileList.extend(filenames)
break
if (len(fileList) > 1):
print "\n\n *********************Required data files are present in the FileShare*********************"
else:
print "\n\n ********************* No files are present to start the Next Run *********************"
はまだ私は最後に、私はpywin32モジュールを使用して私の問題を解決したダウン
mount_command = "net use /user:" + SQLSR_USER + " " + BACKUP_REPOSITORY_PATH + " " + SQLSR_PASS
os.system(mount_command)
backup_storage_available = os.path.isdir(BACKUP_REPOSITORY_PATH)
トライR '\\ファイル共有の\の場所'、または他の、エラーメッセージは何ですか? – Fred
はい、動作します。迅速なお返事をありがとう。 しかし、コードを切断する方法、つまり「バックアップストレージが既に接続されている」というメッセージが表示されたので、「NET USE」オプションでチェックできませんでした。 接続解除スクリプトで提案してください! –
小さな注意:SQLSR_USER/PATHとBACKUP_REPO_PATHは、Webサービスなどのようにリモートで埋め込むことはできません(または完全にチェックすること)。そのos.system呼び出しは、いくつかの厄介なトラブルにつながる可能性があります。 –