I was struggling with writing a script that would help me with a task
of setting original file's creation date on converted files.
Unfortuneatly being very new to powershell I couldn't come up with any
solution.
Scenario is as follows:
Lets say you've made a bunch of family movies with your digital camera.
You've downloaded your movies to PC.Lets say you've converted your
videos to xvid or any other format. Your files' date is set to the day
you've converted them. It would be so nice to have them redate to their
original creation date to be able to quicky determinate when the video
was created.
Situation:
I've got 5 .mpg files in my dir. Then, with any videoconverter I've
converted those files to .avi format. Now there are following files in
my dir:
00001.mpg
00001.avi
00002.mpg
00002.avi
..etc
Could someone please help me with script that would match a pair of
files (00001.mpg and 00001.avi), take creation date from original file
and set converted file's date with it ?
--
mb76pl
Get-ChildItem -Path C:\Test\csvtests -Filter "*.xlsx" | Select Name,
CreationTime, LastWriteTime
Get-ChildItem -Path C:\Test\csvtests -Filter "*.xlsx" | foreach {
$oldname = "$_" -replace ".xlsx", ".csv"
$oldfile = Join-Path -Path c:\test\csvtests -ChildPath $oldname
if (Test-Path -Path $oldfile) {
$old = Get-Item -Path $oldfile
$new = Get-Item $_.Fullname
$new.CreationTime = $old.CreationTime
}
}
Get-ChildItem -Path C:\Test\csvtests -Filter "*.xlsx" | Select Name,
CreationTime, LastWriteTime
i set up something similar with xlsx and csv files
using PowerShell 2
get the creationdate of the xlsx files
get the xlsx files - replace the extension so its .csv. test that a file of
that name exists. if it does then set the creation date on the xlsx file to
match the csv file.
finally check the creation dates on the xlsx files have changed.
This does have a number of steps that could be combined (as someone will no
doubt point out) but I wanted to show the full logic behind what I was doing
in a step by step way
Hope this helps
--
Richard Siddaway
All scripts are supplied "as is" and with no warranty
PowerShell MVP
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk
"mb76pl" wrote:
>
> Hi all,
>
> I was struggling with writing a script that would help me with a task
> of setting original file's creation date on converted files.
> Unfortuneatly being very new to powershell I couldn't come up with any
> solution.
> Scenario is as follows:
> Lets say you've made a bunch of family movies with your digital camera.
> You've downloaded your movies to PC.Lets say you've converted your
> videos to xvid or any other format. Your files' date is set to the day
> you've converted them. It would be so nice to have them redate to their
> original creation date to be able to quicky determinate when the video
> was created.
>
> Situation:
> I've got 5 .mpg files in my dir. Then, with any videoconverter I've
> converted those files to .avi format. Now there are following files in
> my dir:
> 00001.mpg
> 00001.avi
> 00002.mpg
> 00002.avi
> ...etc
>
> Could someone please help me with script that would match a pair of
> files (00001.mpg and 00001.avi), take creation date from original file
> and set converted file's date with it ?
>
>
> --
> mb76pl
> .
>
I'm just about to modify it a little and test it :)
--
mb76pl
Code:
--------------------
Get-ChildItem -Path "<PATH>" -Filter "*.mts" | Select Name, CreationTime, LastAccessTime, LastWriteTime
Get-ChildItem -Path "<PATH>" -Filter "*.avi" | foreach {
$oldname = "$_" -replace ".avi", ".mts"
$oldfile = Join-Path -Path "<PATH>" -ChildPath $oldname
if (Test-Path -Path $oldfile) {
$old = Get-Item -Path $oldfile
$new = Get-Item $_.Fullname
$new.CreationTime = $old.CreationTime
$new.LastWriteTime = $old.LastWriteTime
$new.LastAccessTime = $old.LastAccessTime
}
}
--------------------
--
mb76pl