-4

I have a list of files: Wav16.ogg, Wav17.ogg ... Wav76.ogg
that I want to convert to: a65.ogg, b72.ogg ... b32.ogg

This is what I have so far:

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)

This is the gist of what I am trying to achieve but not sure how to move forward:

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

I've looked around and seen different answers but they all involve changing the names by some factor, not replacing with an arbitrary name: Rename multiple files in a directory in Python

Daniel George
  • 23
  • 1
  • 9
  • Show what you've tried. SO is not a free programming service. – eyllanesc Aug 05 '17 at 00:52
  • It looks like you want us to write some code for you. While many users are willing to produce code for a coder in distress, they usually only help when the poster has already tried to solve the problem on their own. A good way to demonstrate this effort is to include the code you've written so far, example input (if there is any), the expected output, and the output you actually get (console output, tracebacks, etc.). The more detail you provide, the more answers you are likely to receive. Check the [FAQ] and [ask]. – LinkBerest Aug 05 '17 at 00:55

2 Answers2

0

Given the filenames in files named orig and new:

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

Remove the echo if it looks OK.

Given sample inputs of:

orig

file1
file2
file3

new

filea
fileb
filec

The sample output is:

mv file1 filea
mv file2 fileb
mv file3 filec
Jeff Schaller
  • 2,352
  • 5
  • 23
  • 38
  • Hi Jeff, this looks like bash. I am new to this but by orig do you mean Wav*.ogg? and I am not sure what new is. I tried using python to create two arrays of the orig and new .txt files. Is this similar? – Daniel George Aug 05 '17 at 01:20
  • you said "I have made 2 text files containing the old names and the new names"; I called them "orig" and "new", but substitute whatever you called them. – Jeff Schaller Aug 05 '17 at 01:21
  • I am using OS, and readarray is not a bash command. I tried read -t Wav#.txt < Wav#.txt but that give "invalid timeout specification" error – Daniel George Aug 05 '17 at 01:25
0

Found a solution: https://unix.stackexchange.com/questions/250828/script-for-renaming-files-using-text-file-containing-alternate-file-names

Sorry, I didn't know that bash would be more effective

Daniel George
  • 23
  • 1
  • 9