[英]Python script to run a program with a set of files in Windows
我有一個 Windows 應用程序,它將在目錄中的一系列輸入文件上運行。
操作順序是:
我知道我可以使用導入子進程並使用 subprocess.call() 來運行 Windows shell 命令。 我如何以有效的方式實現所有這些步驟?
任何提示都會有所幫助。
感謝和問候,桑托什
根據您的描述,我想這樣的事情應該可行。 只需更改路徑和名稱。
import os
import shutil
files = [r"C:\Path\To\File1", r"C:\Path\To\File2"]
new_names = ["new_file1", "new_file2"]
def x(file, new_name):
program_path = r"C:\Path\To\Program"
save_path = r"C:\Path\To\Save"
new_path = r"C:\NewPath\To\Folder"
os.system("%s -argument %s" % (program_path, file))
shutil.move(save_path, new_path + '/' + new_name)
y = 0
for file_ in files:
x(file_, new_names[y])
y += 1
嘗試提供您到目前為止所做的事情,以便您得到更好的答案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.