dslreports logo
 
    All Forums Hot Topics Gallery
spc
uniqs
115

DataDoc
My avatar looks like me, if I was 2D.
Premium Member
join:2000-05-14
Hedgesville, WV
·StarLink
·HughesNet

DataDoc to HenryNettles

Premium Member

to HenryNettles

Here's my solution

I made a small change to a Windows PowerShell script I found and got it to do exactly what I need. Here's my version:
$colFolder = Get-ChildItem -Recurse "." | Where-Object {$_.mode -match "d"} | Sort-Object Fullname -Descending 
$VerbosePreference = "Continue"
Foreach ($strFolder In $colFolder)
{
Trap [Exception] {
Write-Debug $("TRAPPED: " + $_.Exception.Message);
Write-Verbose "Unable to change date on folder $Folder"
Write-Verbose "Make sure it's not open in Explorer"
Continue
}
$Path = $strFolder.FullName
$Folder = Get-Item $Path
# Get Newest file in folder
$strNewestItem = Get-ChildItem $Path | Sort-Object LastWriteTime -Descending | Select-Object -First 1
 
# Change the date to match the newest file if it doesn't already
If ($strNewestItem.LastWriteTime -ne $Folder.LastWriteTime) {$Folder.LastWriteTime = $strNewestItem.LastWriteTime}
Write-Verbose "Changed:  $Folder"
}
 

I run it in a batch file:
powershell c:\WINDOWS\system32\WindowsPowerShell\v1.0\Examples\folderdate
 

I open a Command window in the folder I need the subfolders' dates changed and run the batch file.

You need to have Windows Powershell installed, of course. This is my first use of PowerShell, so I can't help with your debugging if you change it.

Hope this helps, and thanks to everyone for all the other suggestions.
denon
join:2002-03-04
Frankfurt

denon

Member

How can i do this with the oldest file date in folder(s)?