-1
for file in os.listdir("C:\\Users\\colver\\Desktop\\17-0307"):
if file.endswith(".cdr"):
pfile = ET.parse(file).getroot()
for startTime in pfile.findall('{http://www.securustech.net/private/scn/cdr}startTime'):
start = startTime.text.replace(':' , '-')
for originalDestinationId in pfile.findall('{http://www.securustech.net/private/scn/cdr}originalDestinationId'):
number = originalDestinationId.text
for correlationId in pfile.findall('{http://www.securustech.net/private/scn/cdr}correlationId'):
fileName = correlationId.text
os.rename("C:\\Users\\colver\\Desktop\\17-0307\\"+file, "C:\\Users\\colver\\Desktop\\17-0307\\here\\"+file+".done")
print (file)
new_fileName = (start+"_"+number+"_"+fileName+".ogg")
print (new_fileName)
for fileName in os.listdir("C:\\Users\\colver\\Desktop\\17-0307"):
if fileName.endswith(".ogg"):
os.rename("C:\\Users\\colver\\Desktop\\17-0307\\"+fileName, "C:\\Users\\colver\\Desktop\\17-0307\\here\\"+new_fileName)
os.rename(file, file+".done")
ここに私がドラムアップしたコードがあります。数回実行するとエラーが発生します。また、ディレクトリ内のすべてのファイルについてループスルーしません。それは同じファイルをピックアップし続け、ディレクトリを移動しませんでした。私はPythonに慣れていないので、このコードがきれいで滑らかではないことを認識しています。すべての入力をいただければ幸いです。Pythonは、作業ディレクトリ内のそのファイルタイプのすべてのファイルに対して、ファイル内の内容を使用してファイルの名前を変更します。
あなたのコードや実行している問題の詳細がなくても、あなたの質問に答えるのは難しいです。 – pvg