Author Posts

February 15, 2016 at 2:49 am

Hi

I have an issue, where I have a folder with a large number of images,
These images will be reduced in size by a batch job and be saved to another location.

Now i would like to compare the filenames in both locations and then delete the source files if they are older then x number of days.

February 15, 2016 at 6:35 am

Have you done anything on this at all? Please post your script.

February 15, 2016 at 2:43 pm

Just some pseudocode and hopefully it can help you to start

$souredir="c:\source"
$destdir="c:\dest"
$a=ls c:\source
$b=ls c:\dest

foreach ( $c in $a) {

$sourcefile=$source+$c.name
$destfile=$destdir+$c.name

if ( test-path $destfile ){

$destfiletime=Get-ItemProperty $destfile
if($c.lastwritetime -lt ($destfiletime.AddDays(-10))){
remove-item $sourcefile

}

}else{

#batch job and copy $c to the destination folder
}

}

February 19, 2016 at 1:30 am

I managed to solve part of my problem, but it seems like it only compares the first level folder in the directories and not the files. And so far i have not implemented the date check yet.

$source = Get-ChildItem Y:\sourcedir
$dest = Get-ChildItem V:\destinationdir

$matches = (Compare-Object -ReferenceObject $source  -DifferenceObject $dest -Property Name -ExcludeDifferent -IncludeEqual)

foreach ($file in $matches)
{
        write-host "Deleting file $File"
        
}