Answer the question
In order to leave comments, you need to log in
Copying file attributes (creation date, modification date) from original to copy?
Tell me a powershell script that would change the dates of creation and modification of copy files, taking this information from the attributes of other files (originals), the names are the same, the directories are naturally different, or another situation - the copies have only a different extension, but are located in the same folder as originals.
Answer the question
In order to leave comments, you need to log in
Copying the date is just
$item2.LastWriteTime = $item1.LastWriteTime
the same with CreationTime
and LastAccessTime
But matching $item1
and $item2
is a separate task.
In the simplest version (without subfolders), you can create a hashtable by key, as a key - the name of a
type file
$path1 = 'D:\1'
$items = %{}
Get-ChildItem -Path $path1 | Foreach-Object { $items[$_.basename] = $_ }
$path2 = 'D:\2'
Get-ChildItem -Path $path2 | Foreach-Object {
if ($items.ContainsKey($_.basename)) {
$_.LastWriteTime = $items[$_.basename].LastWriteTime
}
}
There is no standard cmdlet for your conditions in Powershell, but I won’t google for you and look for a ready-made one, if it exists.
1. Form a list of duplicate files by type names like this
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question