Home » Palermices

Sanefile

9 December 2006 No Comment

What is Sanefile?

It is a tool to easily and quickly clean and change a large number of filenames.

The idea started when I started “ripping” my own CD’s and the filenames were all different and full of errors. When I started getting TV downloads from other sources, the issue became a problem. I had to find an efficient way of changing a large number of filenames. Sanefile was the result. Simple, single-purpose and very efficient at it with total exploitation of Tcl’s rich Regular Expression capabilities.

What this tool is NOT: spy-ware, spam-ware, virus or any other crappy stuff.

Sanefile v1.05

HOW TO USE:

In Windows & Mac OS X, first install Tcl using ActiveState’s Tcl distribution if you haven’t already. While you’re at it, find out how easy and powerful it is to script in Tcl [Tcl Wiki].In Unix/Linux start Sanefile with: wish sanefile.tk

In Windows, click on sanefile.tk (Open with Wish).

Afterwards, “Change directory” to load files from a directory you want to clean up. All the files in that directory will be loaded into the lists. On top, you will have the original filenames. On the bottom, you will have the final filenames. The names that have changed are highlighted in RED.

You now can:

  • Remove files from the listing by double-clicking on any filename on the top list
  • Remove files from the list that match a certain criteria by using “List Filters”-> “Remove …”
  • Keep only files on the list that match a certain criteria by using “List Filters”-> “Keep only …”
  • Run your set of user filters (edit userfilter.tcl to expand rules)
  • Edit filenames by double-clicking on the filenames of the bottom list
  • Apply mass filename changes with “Apply rule” (see usage below)
  • “Apply changes” which will change the modified filenames and reload the directory

OR “Reload directory” and abort any changes

FILTERS/RULES/REGULAR EXPRESSIONS:

With Sanefile, you can use the full power of regular expressions. For instance, imagine that you want to filter off all files starting with a A. To use the just A would remove from the list all the files with A in it. Not the solution. If you use ^A (Carat and A) it means that it has to match A only at the beginning of the text.

More examples:


^text       matches "text" in the beginning of the name
text$       matches "text" in the END of the filename
.       matches ANY character
[ ]     range indicator as in:
[a-z]       matches ONE letter "a" to "z"
[a-zA-Z]    matches ONE letter "a" to "z" and "A" to "Z"
[0-9]       matches ONE digit
[^range]    (caret) matches if NOT in the range as in:
[^0-9]      matches if it is NOT a digit
*       operator for repetition
.*      matches everything
[0-9]*      multiple digits
[^a-zA-Z0-9]*   a bunch of everything BUT a letter or digit
escape operator
t       tab
(       when you want to match (
.       when you want to match .
when you want to match  (RARELY DONE! Think why.)
()      used to group expressions
ab*     a followed with multiple b's
(ab)*       multiple ab (different from above!)

^Doors.*([A-Z][0-9]*).*.mp3$         Matches all files starting with Doors, have somewhere in the middle a letter followed by digits and end in ".mp3" 

For a complete explanation of Regular Expressions check out the re_syntax.html file that comes with Tcl or visit these link: http://mini.net/tcl/396.html

Disclaimers: I do NOT provide any guarantee this utility will not delete your most beloved files! Despite not having a single problem ever, this may happen to you.

License: Artistic License 2.0 - http://www.opensource.org/licenses/artistic-license.php

Download: sanefile v1.05 .tgz .zip (7KB, yes KB!)

Comments are closed.