On Mon, 13 Jul 2009, Steve Marak wrote:

> On Mon, 13 Jul 2009, Scott Rohling wrote:
> 
> 
> Some of my co-workers use the Library Reader on their Windows laptops, but 
> I find that even worse than having to rename all the PDFs. I'm sure that 
> says something about the Library Reader, or me, or both, but that's just 
> what I want: the PDF format, with a usable name, available offline on my 
> laptop. Doesn't seem like it should be as much effort as it is.
> 
> Steve

No worries (as our Aussie friends say). Softcopy Librarian downloads the 
PDF files with the "poor" names. But it also downloads the XKS files. The 
XKS files have the title and manual number in it. Using the fsutil command 
that Alan previously mentioned (it's at work, I'm at home). My Perl script 
for Linux follows ( 46 lines) 

#!/usr/bin/perl
use strict;
use warnings;
use Encode qw(from_to);
my ($file,$line,$name,$title,$docid,$shelftitle);
{
        local $/;
        $file=<>; #slurp the entire file
}
$_=$file; #just easier, ya know?
from_to($_,"utf16-be","iso-8859-1"); #convert encoding
tr/\n//d; #remove line-end character.
($shelftitle)=m/<SHELFHEADER[^>]*>.*?<TITLE>([^<]*)<\/TITLE>.*?<\/SHELFHEADER>/;
$shelftitle=" " unless defined $shelftitle;
$shelftitle=~s/ PDF Extended Shelf//;
$shelftitle=~s/&apos;/'/g;
$shelftitle=~s/&quot;/"/g;
$shelftitle=~s/&lt;/</g;
$shelftitle=~s/&gt;/>/g;
$shelftitle=~s/&amp;/&/g;
s/<DOCUMENT /\n<DOCUMENT /g;
s/<\/DOCUMENT>/<\/DOCUMENT>\n/g;
my @line=split /\n/;
foreach $line (@line) {
        next unless $line=~m/^<DOCUMENT /;
        ($name)=$line=~m/NAME="([^"]+)"/;
        $name=~tr/ //d;
        ($title)=$line=~m/<TITLE>(.*?)<\/TITLE>/;
        ($docid)=$line=~m/ DOCID="([^"]*)/;
        $docid=~tr/ //d;
        $name=lc $name;
        $title=~s/&apos;/'/g;
        $title=~s/&quot;/"/g;
        $title=~s/&lt;/</g;
        $title=~s/&gt/>/g;
        $title=~s/&amp;/&/g;
        $title=~tr/:,//d;
#The next 3 lines massage the title a bit.
        $title=~s/z\/OS/zOS/g;
        $title=~s/SMP\/E/SMPE/g;
        $title=~s/[\/ ]/_/g;
#Escape the special characters
        $title=~s/([\(\)'"\\&])/\\$1/g;
        print "$docid.$title\t$name\t$ARGV\t$shelftitle\n";
        print STDERR "ln \"$name.pdf\" $docid.$title.pdf\n";
}

You run the above like:

for i in *.xks;do ./mksym.pl "$i";done >names.txt 2>do_ln.sh

sh <do_ln.sh

Modify as necessary for Windows. I don't know Windows any more, praise 
God!


-- 
Trying to write with a pencil that is dull is pointless.

Maranatha!
John McKown

Reply via email to