Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Simple Perl to find new/changed files  (Read 770 times)

Mephansteras

  • Bay Watcher
  • Forger of Civilizations
    • View Profile
Simple Perl to find new/changed files
« on: July 16, 2010, 01:54:39 pm »

Made a quick script to quickly and easily figure out what files I need to include in my mod, and figured I'd share.

Note that this is perl, so to use this you'll need to have perl installed on your machine. If you're running linux (and maybe mac), you'll need to add the standard #!/usr/bin/perl or whatever to the top.

Basically all this does is go through all the files in the modded version, compare them to the base version, and copy the new and changed files to a new location for easy bundling.

Code: [Select]
### Script to find which files I've modified for Civilization Forge
use File::Compare;
use File::Copy;

my $ModDir = 'C:\Program Files\DF\31.10 CF\raw\objects';
my $BaseDir = 'C:\Program Files\DF\31.10\raw\objects';
my $DestDir = 'C:\Program Files\DF\Civ_Forge_Files';

opendir(DIR, $ModDir);
while ( $filename = readdir(DIR) )
{
      $ModFiles{$filename} = 1;
}
closedir(DIR);

opendir(DIR, $BaseDir);
while ( $filename = readdir(DIR) )
{
      $BaseFiles{$filename} = 1;
}
closedir(DIR);

foreach $ModFile (sort keys %ModFiles)
{
   if ($ModFile eq "." or $ModFile eq "..") { next(); }
   my $ModFilePath = $ModDir . "\\$ModFile";
   my $BaseFilePath = $BaseDir . "\\$ModFile";
   my $NewFilePath = $DestDir . "\\$ModFile";
   if (! $BaseFiles{$ModFile})
   {
      print "$ModFile is new\n";
      &copy($ModFilePath,$NewFilePath) or warn "Cannot copy $ModFilePath to $NewFilePath";
   }
   else
   {
     my $Diff = &compare($ModFilePath,$BaseFilePath);
     #print "    $ModFile -> \"$Diff\"\n";
     if ($Diff)
     {
       print "$ModFile has been altered\n";
       &copy($ModFilePath,$NewFilePath) or warn "Cannot copy $ModFilePath to $NewFilePath";
     }
     else
     {
       print "$ModFile has NOT been altered\n";
     }
   }
}



Logged
Civilization Forge Mod v2.80: Adding in new races, equipment, animals, plants, metals, etc. Now with Alchemy and Libraries! Variety to spice up DF! (For DF 0.34.10)
Come play Mafia with us!
"Let us maintain our chill composure." - Toady One