Say you have a list of .wav files in a particular directory tree, and say you have another pile of .phr files that may or may not be in the same directory tree. The .phr files contain in text the names one or more .wav files. And you need to rename a bunch of the .wav files and have the associated change reflected in any relevant .phr file. How might you choose to set things up to do this "scripted" file renaming?

At present, I'm thinking that it might be done as follows:

  • Recurse the directory (tree) for .wav files and store the filenames in the first in a vector of pair of string.
  • Modify the filename in a temp after the first and store as the second.
  • Perform the renaming/copy-w-mod now or later.
  • Recurse the directory (tree) for .phr files and store the filenames in a vector of string.
  • Loop through the vector of .phr filenamse, open each, and search each line for an instance of the filename text.
    • On match, replace text (via rewrite on-the-fly or whatever).
  • Lather, rinse, repeat as necessary.

Another way I was thinking of doing it was to copy the .wav to both members of the pair on the read and then later transform the second.

Any suggestions?

bulk rename of all the .wav files in one go and updating the text in all the .phr files at another time can leave you in a messy state in the event of a crash (you would have to restart all over again after restoring from backups). you could consider renaming the .wav file and updating its text in the .phr file in one go.

perhaps, using a single map would be easier than having two different vectors. maybe something like this:

a. have a std::map<std::string,std::string> with the original/modified file names as the key and data.

b. recurse the directory (tree) for .wav files and insert the original/modified filenames in the map.

c. i. recurse the directory (tree) for .phr files, open each, and search each line for an instance of the filename text. ii. lookup the file name in the map, if found, rename the .wav file and replace filename text in the .phr file.

d. iterate through the map and rename any remaining .wav files. (which had no entries in the .phr files).

could be a lot easier to do it in python/perl/ruby instead of C++.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.