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

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

Post by *giulia »

Hi

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

I have many folders with mp3 , and some mp3 date were modified by some software
I would like to set the creation and the modified dates of these files to the folder (they are inside)
i know in tc , there is change attribute , but i need to do to a lot of different files that are inside different folders
thanks
love Total Commander , best file manager ever made
User avatar
Horst.Epp
Power Member
Power Member
Posts: 6975
Joined: 2003-02-06, 17:36 UTC
Location: Germany

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

Post by *Horst.Epp »

For files in one tree
Branch view (Ctrl-B)
Select all files (Ctrl-A)
Files Change attributes
Windows 11 Home, Version 24H2 (OS Build 26100.4061)
TC 11.55 RC2 x64 / x86
Everything 1.5.0.1391a (x64), Everything Toolbar 1.5.2.0, Listary Pro 6.3.2.88
QAP 11.6.4.4 x64
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 »

Horst.Epp wrote: 2022-12-20, 08:33 UTC For files in one tree
Branch view (Ctrl-B)
Select all files (Ctrl-A)
Files Change attributes
Hi
i'm looking for a way to select a bunch of folders (30 or 40 folders ) and perform this action
can I do it ?
thanks
love Total Commander , best file manager ever made
User avatar
petermad
Power Member
Power Member
Posts: 16032
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

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

Post by *petermad »

Instead of Ctrl+B you can use Ctrl+Shift+B to open a branch view with only the selected folders.

But in the Change attributes dialog you would need to use a content pluging to find the date of the files' parent folder - and I don't know of such a plugin.

Apart from that - if your files are on an NTFS volume, the folder date does not stay untouched - Windows changes it, whenever files are added to the folder.
License #524 (1994)
Danish Total Commander Translator
TC 11.51 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1391a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
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 »

petermad wrote: 2022-12-20, 12:19 UTC Instead of Ctrl+B you can use Ctrl+Shift+B to open a branch view with only the selected folders.

But in the Change attributes dialog you would need to use a content pluging to find the date of the files' parent folder - and I don't know of such a plugin.

Apart from that - if your files are on an NTFS volume, the folder date does not stay untouched - Windows changes it, whenever files are added to the folder.
hi
yes but windows keep untochouted in NTFS the creation date
and use NirCmd and setfiletime to do the job , it does use variable

Code: Select all

Change the date/time of the specified filename (creation time and modified time) 	nircmd.exe setfiletime "c:\temp\myfile.txt" "24-06-2003 17:57:11" "22-11-2005 10:21:56" 
or maybe someportable tools
thanks
love Total Commander , best file manager ever made
User avatar
petermad
Power Member
Power Member
Posts: 16032
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

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

Post by *petermad »

2giulia

It is easy enough to select the files and change the date to a date that you type in - see: https://madsenworld.dk/tcmd/changefiledates.png - the problem is that you want TC to automatically use the date of the folder which the files are located in - I don't see a solution for that.

If there was a plugin that provided the date of the folder it could have been use by clicking the [+] button (highlighted in blue).
License #524 (1994)
Danish Total Commander Translator
TC 11.51 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1391a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
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 »

Here's a PowerShell script for that:

Save as "Set-Date-of-Parent.ps1" and put it on a button with adjusted path.
Then use Ctrl+B or Shift+Ctrl+B to select your files.

Button:

Code: Select all

TOTALCMD#BAR#DATA
powershell.exe
-NoExit -ExecutionPolicy remotesigned -Command "&{&'C:\PathTo\Set-Date-of-Parent.ps1' -FileList '%L'}"
powershell.exe


0
-1
Script:

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
        }
    }
}
Remove the "-NoExit" after testing.
I use a similar script to restore folder dates after deleting files with something like this:

Code: Select all

$oldFolderDate = $fileItem.Directory.LastWriteTime
$fileItem.Delete()
$fileItem.Directory.LastWriteTime = $oldFolderDate
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-21, 14:18 UTC Here's a PowerShell script for that:

Save as "Set-Date-of-Parent.ps1" and put it on a button with adjusted path.
Then use Ctrl+B or Shift+Ctrl+B to select your files.

Button:

Code: Select all

TOTALCMD#BAR#DATA
powershell.exe
-NoExit -ExecutionPolicy remotesigned -Command "&{&'C:\PathTo\Set-Date-of-Parent.ps1' -FileList '%L'}"
powershell.exe


0
-1
Script:

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
        }
    }
}
Remove the "-NoExit" after testing.
I use a similar script to restore folder dates after deleting files with something like this:

Code: Select all

$oldFolderDate = $fileItem.Directory.LastWriteTime
$fileItem.Delete()
$fileItem.Directory.LastWriteTime = $oldFolderDate
Hi
I will read the folder created time and change the created and modified date of the files inside ,right?
great script , doesn't work under w7 , don't it?
thanks , I will try it
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-21, 15:03 UTC Hi
I will read the folder created time and change the created and modified date of the files inside ,right?
great script , doesn't work under w7 , don't it?
thanks , I will try it
Yes, it will read the file's parent-folder's dates and set them to the file. It should also work with Windows 7 SP1 from what I've read.
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-21, 15:12 UTC
giulia wrote: 2022-12-21, 15:03 UTC Hi
I will read the folder created time and change the created and modified date of the files inside ,right?
great script , doesn't work under w7 , don't it?
thanks , I will try it
Yes, it will read the file's parent-folder's dates and set them to the file. It should also work with Windows 7 SP1 from what I've read.
Hi @ZoSTeR
I have to save in a bat file ,right?

and this script does change the modified date to the creation date of a folder?

Code: Select all

$oldFolderDate = $fileItem.Directory.LastWriteTime
$fileItem.Delete()
$fileItem.Directory.LastWriteTime = $oldFolderDate
thanks ZoSTeR , i will try soon , take care
love Total Commander , best file manager ever made
User avatar
Horst.Epp
Power Member
Power Member
Posts: 6975
Joined: 2003-02-06, 17:36 UTC
Location: Germany

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

Post by *Horst.Epp »

There is no need for any bat file !
As said, store the script, add the provided button
and change the path in this button to the place where you stored the script.
Windows 11 Home, Version 24H2 (OS Build 26100.4061)
TC 11.55 RC2 x64 / x86
Everything 1.5.0.1391a (x64), Everything Toolbar 1.5.2.0, Listary Pro 6.3.2.88
QAP 11.6.4.4 x64
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 »

Horst.Epp wrote: 2022-12-21, 17:36 UTC There is no need for any bat file !
As said, store the script, add the provided button
and change the path in this button to the place where you stored the script.
hi
i have to create a file with the extension ps1 and the file have to be Set-Date-of-Parent.ps1
and there is that it's a powershell , w7 has no powershell if i'm remember right
thanks
love Total Commander , best file manager ever made
User avatar
Stefan2
Power Member
Power Member
Posts: 4281
Joined: 2007-09-13, 22:20 UTC
Location: Europa

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

Post by *Stefan2 »

giulia wrote: 2022-12-21, 17:55 UTC w7 has no powershell if i'm remember right

See Win7 start menu und search for Powershell

Or press Win+R together and type in powershell


If not found, google for "Microsoft Windows Powershell for Windows 7" and just install it
(may also need newer .NET Framework version, but can be read there)

If you need more help, just ask.



Edit:
Windows PowerShell comes installed by default in every Windows, starting with Windows 7 SP1
https://learn.microsoft.com/en-us/skypeforbusiness/set-up-your-computer-for-windows-powershell/download-and-install-windows-powershell-5-1
https://learn.microsoft.com/en-us/powershell/scripting/windows-powershell/install/installing-windows-powershell?view=powershell-7.3

 
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-21, 15:12 UTC
giulia wrote: 2022-12-21, 15:03 UTC Hi
I will read the folder created time and change the created and modified date of the files inside ,right?
great script , doesn't work under w7 , don't it?
thanks , I will try it
Yes, it will read the file's parent-folder's dates and set them to the file. It should also work with Windows 7 SP1 from what I've read.
hi ZoSTeR
it works!
So i can select many different folders once with different creation date and let the script do the job?
thanks ZoSTeR ,take care
I had to change the button script path , i tried to change to %COMMANDER_PATH%\ but it doesn't work , so i have added the total commander full patch and copied inside
so now i can remove the -NoExit and in the script ?

Code: Select all

$answer = Read-Host -Prompt "Change date for $($contentFileList.Length) files?"

if (("y","Y","j","J") -contains $answer)
-NoExit -ExecutionPolicy remotesigned -Command "&{&'C:\PathTo\Set-Date-of-Parent.ps1' -FileList '%L'}" to

Code: Select all

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



-1
Stefan2 wrote: 2022-12-21, 18:36 UTC
giulia wrote: 2022-12-21, 17:55 UTC w7 has no powershell if i'm remember right

See Win7 start menu und search for Powershell

Or press Win+R together and type in powershell


If not found, google for "Microsoft Windows Powershell for Windows 7" and just install it
(may also need newer .NET Framework version, but can be read there)

If you need more help, just ask.



Edit:
Windows PowerShell comes installed by default in every Windows, starting with Windows 7 SP1
https://learn.microsoft.com/en-us/skypeforbusiness/set-up-your-computer-for-windows-powershell/download-and-install-windows-powershell-5-1
https://learn.microsoft.com/en-us/powershell/scripting/windows-powershell/install/installing-windows-powershell?view=powershell-7.3
hi
yes , it woks with w7
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 »

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
    }
}
Post Reply