Jump to content
  • entries
    4
  • comments
    2
  • views
    312

PowerPoint Automation part I


After a hectic couple of weeks, I've finally started looking at the file management thing again. I think this should handle the actual moving and renaming of the file themselves (as yet untested, I plan to test it tonight when I get home). The updating of links in PowerPoint files is currently on hold until either I find a reliable fix for the PowerShell localization problem with Office, or I get around to using PowerShell 2 instead. I'm assuming its fixed there.

 

For anyone interested in the code, its stuck in below.

 

function Move-Files ($OldPath, $NewPath, $Overwrite)
{
$OldPath = $OldPath.TrimEnd('\') + '\'

$Filenames = Get-ChildItem $OldPath -Recurse -Include "*.ppt*"

foreach ($OldFile in $Filenames)
{
 $Keywords = $OldFile.Split(".")
 $Limit = $Keywords.Count() - 3
 $Buildpath = $Path
 $NewFile = $OldFile

 foreach ($Keyword in $Keywords)
 {
  if ($Count -le $Limit)
  {
   $Buildpath = $Buildpath + ($Keyword) + '\'
   $NewFile = $NewFile -replace "$Keyword."

   if (!(Test-Path $Buildpath))
   {
    New-Item $Buildpath -ItemType Directory
   }

   $Count ++
  }

  $OldFile = $Path + $OldFile
  $NewFile = $Buildpath + $NewFile

  if (!(Test-Path $NewFile))
  {   
   Copy-Item -Path $OldFile -Destination $NewFile
  }
  else
  {
   if (!$Overwrite)
   {
    Write-Host -Object "$NewFile already exists - skipping" -ForegroundColor Red -BackgroundColor Black
   }
   else
   {
    Copy-Item -Path $OldFile -Destination $NewFile -Confirm
   }
  }
 }
}
}

Edited by jamesb

0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...