Discussion:
setting converted file's date based from original file's
(too old to reply)
mb76pl
2010-02-07 10:10:01 UTC
Permalink
Hi all

I was struggling with writing a script that would help me with a tas
of setting original file's creation date on converted files
Unfortuneatly being very new to powershell I couldn't come up with an
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 you
videos to xvid or any other format. Your files' date is set to the da
you've converted them. It would be so nice to have them redate to thei
original creation date to be able to quicky determinate when the vide
was created

Situation
I've got 5 .mpg files in my dir. Then, with any videoconverter I'v
converted those files to .avi format. Now there are following files i
my dir
00001.mp
00001.av
00002.mp
00002.av
..et

Could someone please help me with script that would match a pair o
files (00001.mpg and 00001.avi), take creation date from original fil
and set converted file's date with it

--
mb76pl
RichS [MVP]
2010-02-07 14:29:01 UTC
Permalink
Apologies if this posts twice but my broadban connection hiccuped

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
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.
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.
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
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
.
mb76pl
2010-02-07 16:13:23 UTC
Permalink
thank you RichS

I'm just about to modify it a little and test it :

--
mb76pl
mb76pl
2010-02-07 19:17:56 UTC
Permalink
well... it worked like a charm :)
Thanx again RichS




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
Robert Robelo
2010-02-07 20:27:21 UTC
Permalink
PowerShell lets you do this easier through Set-ItemProperty:

Get-ChildItem *.mp3 | ForEach-Object {
$path = $_.Fullname -replace 'mp3$', 'avi'
Set-ItemProperty $path CreationTime $_.CreationTime
Set-ItemProperty $path LastAccessTime $_.LastAccessTime
Set-ItemProperty $path

Loading...