Hack Tool Development

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2004
Posts: 4,341
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Hack Tool Development

 
0
  #1
Oct 30th, 2008
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?
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,089
Reputation: vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all 
Solved Threads: 164
vijayan121 vijayan121 is offline Offline
Veteran Poster

Re: Hack Tool Development

 
0
  #2
Oct 30th, 2008
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++.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC