Hello
I have been using the script that Marc Johnson provided on Powershell.com. I have an issue when the script complets the first time everything runs ok and the files get moved to the archive location. However if the script runs a second time another instance of the archive is produced. In effect an archive inside an archive. I thought producing an if() and else() statments would help this with using test path to stop the second archive locttion from being produced. The current scrip I have is as follows
#Sets the directory in which to search
$Search = "F:\Scripts\Paygate"
#Sets the archive location
$Archive = "F:\Scripts"
#Set the archive path
$ArchivePath = "\Paygate\Archive"
#User can enter the specified date of the age of the files
$Old = 14
$FArcPath = $Archive+$ArchivePath
new-item -path $FArcPath -type directory -ErrorAction SilentlyContinue
if (Test-Path $FArcPath)
{
$Files = get-childitem -recurse | where-object {((get-date) - ($_.Lastwritetime)).days -ge $Old}
# Write-Host $FILES
}
foreach ($File in $Files)
{
# write-host $file.FullName
$MoveDirectory = (Join-Path -path $FArcPath -childpath $File.DirectoryName.SubString($pwd.path.length))
# Write-Host $MoveDirectory
new-item $MoveDirectory -type directory -ea silentlycontinue
$File | move-item -destination {join-path -path $FArcPath -childpath $File.Fullname.Substring($pwd.path.length)}
}
how would I go about just having one archive folder and then appending further results to the folder?
Many thanks in advance