如何将文件列表重命名为新的任意列表

2024-10-08 20:21:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个文件列表:Wav16.ogg,Wav17.ogg。。。Wav76.ogg
我想转换成:a65.ogg,b72.ogg。。。b32.ogg公司

到目前为止,我的情况是:

import os
import numpy as np

OldContent = [i.strip().split() for i in open("OTWGYNmp3/Wav#.txt").readlines()]
oldName    = np.asarray(OldContent)

NewContent = [i.strip().split() for i in open("OTWGYNmp3/Key#.txt").readlines()]
newName    = np.asarray(NewContent)

这就是我努力实现但不确定如何前进的要点:

for i in len(newName):
    os.rename(oldName[i], newName[i]) 

我环顾四周,看到了不同的答案,但它们都涉及到通过某种因素更改名称,而不是用任意名称替换:Rename multiple files in a directory in Python


Tags: inimporttxtforosnpopensplit
2条回答

给定名为orignew的文件中的文件名:

readarray -t orig < orig
readarray -t new < new
for((i=0; i < ${#orig[*]}; i++))
do
  echo mv   "${orig[i]}" "${new[i]}"
done

如果echo看起来正常,请将其移除。你知道吗

给定样本输入:

原始

file1
file2
file3

新建

filea
fileb
filec

示例输出为:

mv file1 filea
mv file2 fileb
mv file3 filec

相关问题 更多 >

    热门问题