Page 1 of 1
can xyplorer change the date of the filder using the folder date?
Posted: 21 Dec 2022 16:15
by giuliastar
Hi
is there a way to change the files creation and modified date using their folder creation date?
a classic example is ,a folder and a bunch of mp3 inside ,some of them has the modified date changed by a program , would like to change their created and modified date using the createdion date folder (not modified because windows change it )
and would really cool ,if could be done with several folder , like 10 folders ,each with files inside
thanks
take care
Re: can xyplorer change the date of the filder using the folder date?
Posted: 21 Dec 2022 16:41
by highend
Sure, script it^^
Re: can xyplorer change the date of the filder using the folder date?
Posted: 21 Dec 2022 17:03
by giuliastar
highend wrote: ↑21 Dec 2022 16:41
Sure, script it^^
Hi
i don't know how script it
Re: can xyplorer change the date of the filder using the folder date?
Posted: 21 Dec 2022 18:00
by Horst
This powershell script does it if you give it a list of files as argument.
So your scripting effort in XY will be small.
Code: Select all
Param(
[Parameter(Mandatory=$True)]
[ValidateNotNullOrEmpty()]
[string]$FileList
)
$contentFileList = Get-Content -LiteralPath $FileList
$answer = Read-Host -Prompt "Change date for $($contentFileList.Length) files?"
if (("y","Y","j","J") -contains $answer)
{
Write-Output "Changing dates"
foreach ($filePath in $contentFileList)
{
#Check if path exists and is a file
if (Test-Path -LiteralPath $filePath -PathType Leaf)
{
Write-Output $filePath
$fileItem = Get-Item -LiteralPath $filePath
#Set the Dates of Parent Folder
$fileItem.CreationTime = $fileItem.Directory.CreationTime
$fileItem.LastAccessTime = $fileItem.Directory.LastAccessTime
$fileItem.LastWriteTime = $fileItem.Directory.LastWriteTime
}
}
}
Re: can xyplorer change the date of the filder using the folder date?
Posted: 21 Dec 2022 18:58
by giuliastar
Horst wrote: ↑21 Dec 2022 18:00
This powershell script does it if you give it a list of files as argument.
So your scripting effort in XY will be small.
Code: Select all
Param(
[Parameter(Mandatory=$True)]
[ValidateNotNullOrEmpty()]
[string]$FileList
)
$contentFileList = Get-Content -LiteralPath $FileList
$answer = Read-Host -Prompt "Change date for $($contentFileList.Length) files?"
if (("y","Y","j","J") -contains $answer)
{
Write-Output "Changing dates"
foreach ($filePath in $contentFileList)
{
#Check if path exists and is a file
if (Test-Path -LiteralPath $filePath -PathType Leaf)
{
Write-Output $filePath
$fileItem = Get-Item -LiteralPath $filePath
#Set the Dates of Parent Folder
$fileItem.CreationTime = $fileItem.Directory.CreationTime
$fileItem.LastAccessTime = $fileItem.Directory.LastAccessTime
$fileItem.LastWriteTime = $fileItem.Directory.LastWriteTime
}
}
}
hi @Horst
should i create a button or can i save to a file ? May i know which extension should i use if i want a file?
thanks a lot Horst
Re: can xyplorer change the date of the filder using the folder date?
Posted: 21 Dec 2022 21:58
by Horst
For example store the script under the name Set-Date-of-Parent.ps1
Then try to read the help or examples in the script forum how to get a list of files into a file.
This file would be the parameter for a button which invokes the script.
Example without much scripting, create a paper folder with your files and use this as parameter.
Re: can xyplorer change the date of the filder using the folder date?
Posted: 21 Dec 2022 22:09
by admin
This will change all 3 dates of the selected-and-focused list item to the dates of its parent folder:
Code: Select all
$item = <curitem>; $parent = gpc($item, "path"); timestamp , $parent, $item;
You can run it through the address bar. Is that what you wanted?