A script to name files by Bates number

This script was made because I often would receive PDFs named by their Bates range, or even just the first Bates number of the file, with gaps in numbers between the files. In these cases I wanted to be able to bring the files up in Sanction or Trial Director by typing the bates number, I did NOT want to rename each page document by document.

If files as such are named by first Bates number (a regular expression rename using “renameit” can easily chop off the trailing part if some of them are named by range), and then run through one of the previously posted scripts (monochrome or color PDF to tiff conversion in my preferred format/directory structure), running this script in the “To Add” folder will create a new folder “ZZAdd” with all Tiff files named by Bates number. Drag this folder into either Sanction, or Trial Director, and have an easy time bringing up your documents.

Please note, the script needs mild editing to adjust for the numbering format of a specific run (see comments, currently setup for P#### format).

Similar to previous postings, it also requires Cygwin, this time only the core and Bash I believe.

#!/bin/bash
#Script to rename files by bates number from "script color"
#assumes filename is in format prefix###### whenre ###### is the starting bates number of a sequential document

#setup field separator
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")

#Make folder to hold all files
mkdir ZZAdd

#Loop over directories (should be named by PDF that was named by starting bates
for dirname in `ls |grep P`; do
    echo $dirname
#regex designed to parse the number out of the folder name, must be edited appropriately
    batesnum=`echo $dirname| sed 's/[P0]*\(.*\)/\1/g'`
#Enter folder with tiffs named bates then bates###### where ###### is incremental pagenumber from original PDF
    cd ./$dirname
#loop over Tifs, increment bates with each step, copy tiffs to to new folder
    for filename in `ls *tif` ; do
#new names for files, remember to add prefix back, and set number of zeros
        newname=`printf "P%04d" $batesnum`
        cp $filename ../ZZAdd/$newname.tif
        batesnum=$((batesnum+1))
        done
    cd ..
    done


#fix field separator
IFS=$SAVEIFS

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>