in reply to Re^2: rename files
in thread rename files

Your solution does meet the spec, but it's really just a disaster waiting to happen. Keeping the directory contents and the names file in sync will be a challenge and really seems unmaintainable.

I'd really be interested in what pbaumgar is actually trying to solve here.

Replies are listed 'Best First'.
Re^4: rename files
by mr_mischief (Monsignor) on Apr 08, 2009 at 17:03 UTC
    The situation which pbaumgar is in is certainly a mess.

    If possible, RoyCrowder's solution is preferable so there is no file to synchronize. Without being sure the rest of the data meets the same restrictions, though, we can't tell if it does do the right thing.

    Either way, I would hope that this is a one-time conversion and not something that has to be repeated. Hopefully if there's an ongoing process that produces these files it will in the future just output them in the new naming scheme rather than requiring repeated conversions.

    As you say, it could be really helpful to know more about the situation.

Re^4: rename files
by RoyCrowder (Monk) on Apr 08, 2009 at 18:01 UTC
    lostjimmy hit the nail on the head. That is why I wrote my snippet in such a manner as to exclude any use of an external names file. My snippet below will read the directory instead of using a pre-written sorted file.

    The Web is like a dominatrix. Everywhere I turn, I see little buttons ordering me to Submit. (Nytwind)
      I've said in two places now that if the desired new names all follow from the example that your solution is preferable to one that uses the separate file. If the desired new names do not follow from the example, then you've changed the behavior by deviating from the spec.

      Someone shouldn't have named a bunch of files with just digits to begin with. Just naming them "testfile1" through "testfilen" actually isn't much better for sake of description. One would hope there are no sequence holes in the new naming scheme at least, but without pbaumgar saying so we can't be sure.

Re^4: rename files
by pbaumgar (Acolyte) on Apr 08, 2009 at 23:49 UTC
    Thank you to everyone for the pointers in getting this working. Here's what I'm trying to solve:

    I have about 500 text files from an old wiki. The file names are all numbers. I have a dump of from the mySQL database of the wiki, from which I extracted the descriptions of each file. I want to rename each file to it's corresponding description. For example I have file '2', which the description is 'Server Build'. I want to rename the files to their description so I can then import them into a new wiki. The new wiki has a import utility script which you can pass it a file name and a title, however it only accepts one file at time.

    Thanks again everyone, I think have enough to get me going.