[Tutor] Python Saved the Day

Robert Sjoblom robert.sjoblom at gmail.com
Sun Dec 4 12:12:17 CET 2011


I had a situation where there were 300+ files needed to be renamed to
standardized naming; the problem was that each group that had worked
on the project had their own naming convention and group tag. One
group had date_number_subnumber_grouptag where others might have
grouptag_date_number_subnumber and others dropped the grouptag and
subnumbers and it was a very messy deal. I wrote a script that fixed
the naming to date_number_subnumber_abbreviated-grouptag.

The resulting script is a hack, for sure (there was simply no way to
build a script that could deal with all variations of the names at
once, so it had to run several times checking for different things).
Instead of working directly with the files while trying things out, I
wrote a simple script that yanked all the filenames and created empty
copies of the files with a simple list comprehension, then I could try
out the script without using the real files (or copying the actual
files with content, which would have taken much longer).

There was one file, after the script ran, that I just couldn't get to
without specifically naming it in the script. But renaming one file
manually instead of 300+ feels like an acceptable cost.

-- 
best regards,
Robert S.


More information about the Tutor mailing list