Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to change the folder time and date (the attribute properties) via a DOS Batch file, VBS, PERL or a Powershell script?


FOLDER: F1, F2, F3... SUB-FOLDER: S1, S2, S3 ... FILES: L1, L2.....Ln

Say the current time on folders, sub-folders and files is like this:

Jan-01-2000 1:00AM

Then I add a new sub-folder called S7 with time Jan-01-2001 23:00PM

This should automatically cause the top folder (F1) to have attribute properties copied from the latest file (or sub-folder) time stamp. That means the F1 folder should be now Jan-01-2001 23:00PM from Jan-01-2000 1:00AM because it now inherits the time/date attributes from S7.

Is a VB, VBS, Powershell Script, or Batch file doable?

share|improve this question

migrated from Aug 10 '12 at 23:26

This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems.

Possible? Certainly. Worth the effort, well that would be up to you and why you think you need to do this. There are two methods that immediately come to mind. The first is to have a scheduled task that runs every hour or so. The task would get all the subfolders and sort them by LastWriteTime. Then it would grab the date from the most recent and set the parent folder's LastWriteTime to that. The second method would be to register a WMI event synce that would essentially do the same thing any time anything was added to the parent folder. – EBGreen Aug 15 '12 at 17:35

Powershell can walk through a folder and find the latest written file/folder. You can then use it to set it for the folder.

$Path = 'c:\temp'

(Get-Item $Path).LastWriteTime = (Get-ChildItem $Path -Recurse | Sort-Object -Property LastWriteTime -Descending)[0].LastWriteTime

You can save the above code and run it periodically using Task Scheduler or by using a file monitoring tool to trigger it.

share|improve this answer

You must log in to answer this question.