943,912 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 624
  • C++ RSS
Oct 30th, 2008
0

Hack Tool Development

Expand Post »
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?
Similar Threads
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Oct 30th, 2008
0

Re: Hack Tool Development

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++.
Reputation Points: 1159
Solved Threads: 285
Posting Virtuoso
vijayan121 is offline Offline
1,606 posts
since Dec 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: c++ very basic, convert a string to an integer
Next Thread in C++ Forum Timeline: OpenGL? Graphics? Help please





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC