P
P
Pullout2018-02-21 12:27:42
PowerShell
Pullout, 2018-02-21 12:27:42

How to determine how many days a file is stored in a folder (CMD or powershell)?

Good afternoon friends!
I ask you to help in one very important, but simple matter.
There is file storage (video recordings), OS - Windows 7 pro, there is a folder in which folders are created every day and files with *.mp4 extension are saved in them during the day.
You need to find the oldest file in the folder and determine how many days it is.
Example:
Folder: D:\Archive\
It creates folders like: 2018-02-19 18.00.56.459
They have a bunch of other folders. in which files with a certain extension are also created daily.
What the script should be able to do:
Scan the D:\Archive folder for files with a certain extension, determine the oldest file, and calculate how many days it has been stored there.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MaxKozlov, 2019-10-31
@MaxKozlov

If you do not bind to folder names, but only to the time the file was modified

Get-ChildItem D:\Archive\ -Recurse -File *.mp4 |
  Sort-Object LastWriteTime | 
  Select-Object -First 1 |
  ForEach-Object { (Get-Date) - $_.LastWriteTime }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question