makeFileDatabase.pl
- $START_DIRECTORY='/Zvon/ZvonXMLSource';
- $DATABASE_DIRECTORY = '/Zvon/FileCentral';
- $ROOT_WEB = 'C:/Zvon';
- $ID_PREFIX='zvon';
- use File::Path;
- use File::Basename;
- use Cwd;
- use Zvon::XML_ID;
- sub directory
- {
- my (@list, $item);
- opendir DIR,".";
- @list = readdir DIR;
- #remove . and ..
- shift(@list);
- shift(@list);
-
- foreach $item (@list)
- {
- if (-f $item) {file($item);}
- if (-d $item) {
- chdir($item);
- directory($item);
- chdir ("..");
- }
- }
- }
- sub file
- {
- if($_[0]=~/\.xml/) {
- if(!(open FILE, $_[0])){print "Open \n$_[0] failed";}
- read FILE, $xmlFile, 10000; #the id is somewhere at the start
- if ($xmlFile=~/$ID_PREFIX\d{17}/)
- {
- $id=$&;
- $idFile = XML_ID::getIDFilefromID($&);
- $fileDir = cwd();
- $fileDir =~ s/$ROOT_WEB//;
- $idList{$idFile}= "$idList{$idFile}$id=$fileDir/$_[0]\n";
- }
- else
- {
- print "\n File $_[0] does not have an ID";
- }
- }
- }
- chdir $START_DIRECTORY;
- directory();
- print "\n\n";
- while ( ($idFile, $value) = each %idList)
- {
- $idDir=dirname($idFile);
- if(!(-d $idDir)) {mkpath($idDir,"true");};
- open OUT, ">$idFile";
- print OUT $value;
- close OUT;
- }
-
-