database question
Kevin D. Clark
kclark at CetaceanNetworks.com
Sun Nov 23 23:54:26 EST 2003
Vince McHugh writes:
> I am supplying them with scanning equipment that can
> produce a pdf file with "meta data" in the file name.
> It will look something like this:
>
> info1_info2_info3_info4_info5.pdf
>
> The info1 - info5 will be replaced by specific meta
> data with information about the PDF file.
>
> Now the question, We would like to know if there is
> a way to write a script that would strip out the info
> fields separated by underscores (this separator could
> be changed to any valid character) and populate
> database fields, possibly using MySQL.
Sure, this would be easy. I would highly recomend using Perl and
Perl's DBI modules for this.
In your particular case, a snippet of Perl code like this might be
useful:
use strict; # turn on handy warnings
my $filename;
$filename = "aaa_bbb_CCC_ddd_eee.pdf";
my($info1, $info2, $info3, $info4, $info5) =
$filename =~ m{([a-zA-Z]*)_
([a-zA-Z]*)_
([a-zA-Z]*)_
([a-zA-Z]*)_
([a-zA-Z]*).pdf}x;
Now you'd got info1 - info5 -- putting this into a DB is a matter of
programming. If I am hand-waving here, this is because this task is
highly dependent on how your DB is setup. There's plenty of
documentation available for this task.
> The second thing that we would like the script to do
> is to move the file from one folder to another
> possibly based one one of the info fields name. For
> instance if the info1 field is a customers name or
> number that the file would be moved to a folder with
> that name.
Depending on what you need to do, the following Perl code might
suffice:
rename($filename, $info1)
|| die "Couldn't rename $filename to $info1: $!\n";
Regards,
--kevin
--
Kevin D. Clark / Cetacean Networks / Portsmouth, N.H. (USA)
cetaceannetworks.com!kclark (GnuPG ID: B280F24E)
alumni.unh.edu!kdc
More information about the gnhlug-discuss
mailing list