Change folder modified to date as same to the files inside

Well ,

The topic says it all. Can opus help me in that.

I have a scenarios where I moved my (movie+music) collection to a rescue harddisk and then back to the original harddisk using Directory Opus as the copying tool.

Now I did fill the original harddisk at various times with media content. When I browse these contents on my NMT Media Center and sort ascend/descend based on the folder date, I can easily find all the recent or the oldest media.

During this rescue procedure , when the original media is copied back to its place (from the rescue harddisk) , I notice that all folders have the modified date as of today (or the day it was done). As a result when I sort the media contents on my media theater, all folders are lined up at the same level, making it virtually impossible to sort the most recent media.

I have noticed that the modified date of the folders is set to the current date ( when the copying took place), however the media files inside (usually one per folder) retain their original modified date (the actual date when they were transferred).

So is there a way or a custom script which can be made to check all the folder contents, and set the MODIFIED DATE of the FOLDER as equal to the most recent MODIFIED DATE of the FILES (maybe more than one in some folders) found inside each folder.

I hope I am able to explain my requirement.

Would appreciate expert guidance.

If the files don't all have the same date/time would you care which file's timestamp was ultimately used for the parent folder?

I did mention it, if files inside the folders have different dates then I would want the most latest or recent date, to be used as the modified date for the parent folder.

Thanks.

I would like that too . . .
Have long been hesitating to post a similar request, but did not, whilst more or less assuming that this option would serve my purpose only and others won't mind.
Redate the folder date based on either Exif-dates or the most recent filedate.
Have been checking out half a dozen of filerenamers, but none of them has such an option.

If this could be done I would think this would be a never ending process for you on NTFS file systems.

Because Windows changes the last modified folder dates each time it does something to anything inside of an NTFS folder.

Yes. This is an "interesting" design feature. Simply navigating to an NTFS folder, opening a file and closing without change, has the unfortunate side effect of updating the folder's time stamp. Like many others, I would dearly love to be able to switch this behaviour off but I expect we are stuck with it until something better comes along to supersede NTFS.

Regards, AB

Leo,

Need your help mate.

As far as having a continuous loop of refreshing the folder dates, because file modified date is updated every time a file is clicked, it seems kinda distant to me.

Reason being I am requesting a script or routine which would be triggered manually, upon user request to perform the desired action. If the script is not called, it is not supposed to keep an automatic check of file timestamps and match the folder timestamps whenever an update is detected.

Still looking for it, is RegEx the answer...??? I dont know a clue about it anyways.

Thanks.

Was able to work my way by using the Windows Power Shell (built in Windows 7) or you can download otherwise as well.

The following script works for me (have tested it).

Get-ChildItem $root | Where-Object {$_.PSIsContainer} | Foreach-Object{

# get the oldest file for the current directory object
$oldest = Get-ChildItem $_.FullName | Sort-Object LastWriteTime | Select-Object LastWriteTime -Last 1

if($oldest)
{
# oldest object found, set current directory LastWriteTime
$_ | Set-ItemProperty -Name CreationTime -Value $oldest.LastWriteTime 
$_ | Set-ItemProperty -Name LastWriteTime -Value $oldest.LastWriteTime
}
else
{
# current directory is empty, directory LastWriteTime is left unchanged
Write-Warning "Directory '$($_.FullName)' is empty, skiping..."
}
}

The compiled script is attached. Just download it and run it in the INTENDED root directory (with the target subfolders) in the Power Shell Console. It runs by .\date command in the powershell console.

It will update the "Created" and "Last Modified" date to the latest date of child objects (files inside) found inside each subfolder.

Try and post your results.

Thanks.

Hello All,

Have tried it with various folders having varied number of files inside. It is working correctly. The forum did not allow me to attach the compiled script (date.ps1). So trying to attach it in a ZIP file.

Just download it , copy and run it in the INTENDED root directory (with the target subfolders) in the Power Shell Console. It runs by ".\date" command in the powershell console.

Also posting and INF file, which would make the life easier for you by adding the shell context menu with an option to open PowerShell console in the subfolder. (Similar to having the 'Command Prompt here') . Just right click and install it, it would be active instantly, provided you are using Windows 7 and have the PowerShell installed at the default location.

There is one observation however, it is working only with the locally attached storage (USB, SATA, eSATA) harddisks. I have tried running it in a network mapped folder with all the write permissions, and the folder dates were not updated. Will keep trying for it, and will post the result.

Please give feedback here so it can be improved if needed.

Thanks.
powershellhere.zip (741 Bytes)
date.zip (453 Bytes)

Hey, thanks for your script. I just tested it both on Local and on a NAS and it worked. The difficulty is all the digital certificates. Once I set it to unrestricted in powershell, I could run it from the NAS. If you set the policy to remotesigned, it can not run it from a NAS. My next step would be to actually sign the script and set back the policy to restricted.

I have 2 more variant scenarios for your script.

1- One that would set the date to the newest file.
2- The second would be that it look for a specific file in each folder and use its date. Like a seen.txt in each folder.

Could you help me please here. I want for the script to look for a file name date_seen and change the folder timestamp to that.

I have replaced one line with this:

$oldest = Get-ChildItem $_.FullName | where-Object {$_.name -match "date_seen"}

this works, however if the folder name contains [] it doesn't and my folder names have these two characters in them.
Any ideas?

I just figured it out. Just add -literalPath and it ignores wildcards.

Also the original script sets the date to the newest file and not the oldest file.
Is it possible to do the same thing with DOpus scripts and make it easy?
Because with powershell you have the execution policy problem.

Okay...

I know . . .

This is a very old thread, but, as for the request: same for me: Yes! It would be nice to have this available as a button, i.e. click on a folder, click on the button, done!
Have no idea about Powershell, it seems to be on my pc, guess I can start it, but then what ..?

=

I know this thread is old, but I would definitely +1 this feature request. A folder modified date with no correlation to the files inside has been a long-time pet peeve of mine -- annoying enough for me to register for the forum after being a user for 20+ years :slight_smile:

Thank you! I guess I should have asked sooner...

I also installed the alternative script (ColFolderDate.js.txt) and it offers column sorting by Oldest (Create) and (Modified), which is also helpful. Is there a recursive version of these? I am trying to find the oldest file within a subfolder as well as I organize my old photos.

It'd be fairly easy to modify my script to do that. Don't have time just at the minute, though.

2 Likes

No rush of course but certainly would appreciate it. Almost all of my old photos appear in folders from 2013 and I would love to sort them more accurately!

Thanks for the quick responses and on a weekend.

Globally replacing Newest with Oldest and < with > in Leo's script should be sufficient :slight_smile:

2 Likes

Up front I am not sure if this is what you are looking for, but FWIW I am using a small tool for this for I don't know how long. A toolbar button.
Select a (parent)folder, click on the button (or context menu item if you like) re-date the folder after the oldest newest file dates inside modified or created or both. When clicking on a parent folder with sub folders I can select 'Recurse' to take the oldest or newest date within any sub sub folder.

Below example - parentfolder "Change folder date after dates of files inside" with a few sub folders.
Folder date 11-06-2021
In some sub folder a file is dated 31-07-2021
Run SetFolDate to Newest, Recursive
Parentfolder date changed accordingly.
Obviously same goes for old date files (see 2)