is there a way to change the date of bunch of files according the folder date?

English support forum

Moderators: Hacker, petermad, Stefan2, white

giulia
Senior Member
Senior Member
Posts: 328
Joined: 2013-09-14, 05:33 UTC
Location: Europe

Re: is there a way to change the date of bunch of files according the folder date?

Post by *giulia »

ZoSTeR wrote: 2022-12-22, 10:02 UTC Here's the minimized version without confirmation using the Commander_Path environment variable:

Button:

Code: Select all

TOTALCMD#BAR#DATA
powershell.exe
-ExecutionPolicy remotesigned -Command "&{&"""$env:COMMANDER_PATH\Tools\PowerShell\Set-Date-of-Parent.ps1""" -FileList '%L'}"
powershell.exe
Set Date of Parent

1
-1
Script:

Code: Select all

Param(
    [Parameter(Mandatory=$True)]
    [ValidateNotNullOrEmpty()]
    [string]$FileList
)

$contentFileList = Get-Content -LiteralPath $FileList

foreach ($filePath in $contentFileList)
{
    if (Test-Path -LiteralPath $filePath -PathType Leaf)
    {
        $fileItem = Get-Item -LiteralPath $filePath
        $fileItem.CreationTime   = $fileItem.Directory.CreationTime
        $fileItem.LastWriteTime  = $fileItem.Directory.LastWriteTime
    }
}
Hi ZoSTeR
but could be work if i click on the folders and the scripts changed all the date of the files inside?
I mean select a bunch of folders (like 10 folders or more) with different creation date and let the script change all the date of the files inside according to the folders?
because seems the script does work only if i select the folder inside a folder
thank you so much
love Total Commander , best file manager ever made
User avatar
ZoSTeR
Power Member
Power Member
Posts: 1050
Joined: 2004-07-29, 11:00 UTC

Re: is there a way to change the date of bunch of files according the folder date?

Post by *ZoSTeR »

giulia wrote: 2022-12-23, 07:08 UTC but could be work if i click on the folders and the scripts changed all the date of the files inside?
You talked about files before, but sure:

Button:

Code: Select all

TOTALCMD#BAR#DATA
powershell.exe
-ExecutionPolicy remotesigned -Command "&{&"""$env:COMMANDER_PATH\Tools\PowerShell\Set-FileDate-to-FolderDate.ps1""" -FolderList '%L'}"
powershell.exe
Set File Date to Folder Date

1
-1
Script "Set-FileDate-to-FolderDate.ps1":

Code: Select all

Param(
    [Parameter(Mandatory=$True)]
    [ValidateNotNullOrEmpty()]
    [string]$FolderList
)

$contentFolderList = Get-Content -LiteralPath $FolderList

foreach ($folderPath in $contentFolderList)
{
    if (Test-Path -LiteralPath $folderPath -PathType Container)
    {
        $folderItem = Get-Item -LiteralPath $folderPath
        $fileItems = Get-ChildItem -LiteralPath $folderPath -Recurse
        foreach ($fileItem in $fileItems)
        {
            $fileItem.CreationTime = $folderItem.CreationTime
            $fileItem.LastWriteTime = $folderItem.LastWriteTime
        }
    }
}
This is recursive and please test it before using it on real data
giulia
Senior Member
Senior Member
Posts: 328
Joined: 2013-09-14, 05:33 UTC
Location: Europe

Re: is there a way to change the date of bunch of files according the folder date?

Post by *giulia »

ZoSTeR wrote: 2022-12-23, 23:55 UTC
giulia wrote: 2022-12-23, 07:08 UTC but could be work if i click on the folders and the scripts changed all the date of the files inside?
You talked about files before, but sure:

Button:

Code: Select all

TOTALCMD#BAR#DATA
powershell.exe
-ExecutionPolicy remotesigned -Command "&{&"""$env:COMMANDER_PATH\Tools\PowerShell\Set-FileDate-to-FolderDate.ps1""" -FolderList '%L'}"
powershell.exe
Set File Date to Folder Date

1
-1
Script "Set-FileDate-to-FolderDate.ps1":

Code: Select all

Param(
    [Parameter(Mandatory=$True)]
    [ValidateNotNullOrEmpty()]
    [string]$FolderList
)

$contentFolderList = Get-Content -LiteralPath $FolderList

foreach ($folderPath in $contentFolderList)
{
    if (Test-Path -LiteralPath $folderPath -PathType Container)
    {
        $folderItem = Get-Item -LiteralPath $folderPath
        $fileItems = Get-ChildItem -LiteralPath $folderPath -Recurse
        foreach ($fileItem in $fileItems)
        {
            $fileItem.CreationTime = $folderItem.CreationTime
            $fileItem.LastWriteTime = $folderItem.LastWriteTime
        }
    }
}
This is recursive and please test it before using it on real data
Hi ZoSTeR
I want to change the creation and modified date of the files inside the folder using the creation folder date
I would like to ask if i can select many folders (with different date and with different files inside ) and let the script read the creation date of each folder and change the files date
for example
folder1 creation date (with day and month... 2019 -> bunch of mp3
folder2 ....creation date (with day and month. 2022)-> bunch of flac
folder3 ...createion date (with day and month. 2018) -> bunch of aac files

select folder1 , folder2 and folder3 and let the script handle and change the bunch of mp3 to creation date folder1 2019 , the bunch of flac to creation date folder2 and the bunch of aac files to creation date folder 3
sorry english is not my native language
thanks
love Total Commander , best file manager ever made
User avatar
ZoSTeR
Power Member
Power Member
Posts: 1050
Joined: 2004-07-29, 11:00 UTC

Re: is there a way to change the date of bunch of files according the folder date?

Post by *ZoSTeR »

That's what the new script above does. Select a bunch of folders and press the button.
The dates of the files in them will be changed according to their parent folder.

Maybe you want to change

$fileItem.LastWriteTime = $folderItem.LastWriteTime
to
$fileItem.LastWriteTime = $folderItem.CreationTime
giulia
Senior Member
Senior Member
Posts: 328
Joined: 2013-09-14, 05:33 UTC
Location: Europe

Re: is there a way to change the date of bunch of files according the folder date?

Post by *giulia »

ZoSTeR wrote: 2022-12-24, 20:29 UTC That's what the new script above does. Select a bunch of folders and press the button.
The dates of the files in them will be changed according to their parent folder.

Maybe you want to change

$fileItem.LastWriteTime = $folderItem.LastWriteTime
to
$fileItem.LastWriteTime = $folderItem.CreationTime
hi ZoSTeR
but it doesn't work
i have tried to copy some files inside a folder changed the files date , clicked on the folder and run the script
it doesn't change the files dates :? :(
with or without
Maybe you want to change

$fileItem.LastWriteTime = $folderItem.LastWriteTime
to
$fileItem.LastWriteTime = $folderItem.CreationTime
love Total Commander , best file manager ever made
User avatar
ZoSTeR
Power Member
Power Member
Posts: 1050
Joined: 2004-07-29, 11:00 UTC

Re: is there a way to change the date of bunch of files according the folder date?

Post by *ZoSTeR »

 
Did you modify the path to the script in the command parameter to the actual path on your system?

Then add "-NoExit" in front of the command parameter to see if there are any errors.

You can add "Write-Output $variableName" in the script to check further.
Post Reply