setting converted file's date based from original file's

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
0
mb76pl
2/7/2010 10:10:01 AM
windows.powershell 690 articles. 0 followers. Follow

4 Replies
1201 Views

Similar Articles

[PageSpeed] 35

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


"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
> .
> 
0
Utf
2/7/2010 2:29:01 PM
thank you RichS,

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


-- 
mb76pl
0
mb76pl
2/7/2010 4:13:23 PM
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
0
mb76pl
2/7/2010 7:17:56 PM
UG93ZXJTaGVsbCBsZXRzIHlvdSBkbyB0aGlzIGVhc2llciB0aHJvdWdoIFNldC1JdGVtUHJvcGVy
dHk6DQoNCkdldC1DaGlsZEl0ZW0gKi5tcDMgfCBGb3JFYWNoLU9iamVjdCB7DQogJHBhdGggPSAk
Xy5GdWxsbmFtZSAtcmVwbGFjZSAnbXAzJCcsICdhdmknDQogU2V0LUl0ZW1Qcm9wZXJ0eSAkcGF0
aCBDcmVhdGlvblRpbWUgJF8uQ3JlYXRpb25UaW1lDQogU2V0LUl0ZW1Qcm9wZXJ0eSAkcGF0aCBM
YXN0QWNjZXNzVGltZSAkXy5MYXN0QWNjZXNzVGltZQ0KIFNldC1JdGVtUHJvcGVydHkgJHBhdGgg
TGFzdFdyaXRlVGltZSAkXy5MYXN0V3JpdGVUaW1lDQp9DQoNCi0tIA0KUm9iZXJ0

0
Robert
2/7/2010 8:27:21 PM
Reply:

Similar Artilces:

Set RowSource
Is it possible to set the RowSource for a ComboBox based on a condition? For ComboBox1 I would like to set the RowSource as follows: If ActiveWorkbook.Worksheets("FR Launch Sheet").Range("B3") = Sat then Rowsource would be 'Routes'!$E$2:$E$61 If ActiveWorkbook.Worksheets("FR Launch Sheet").Range("B3") = Sun then Rowsource would be 'Routes'!$H$2:$H$61 If ActiveWorkbook.Worksheets("FR Launch Sheet").Range("B3") did not equal Sat or Sun then Rowsource would be 'Routes'!$B$2:$B$61 Hi ...

Set Default Calendar in Outlook 2003
How can I change the default calendar in Outlook 2003? I have two calendars showing. One was created when I installed Outlook. The other was created when I installed Outlook Conector and added my MSN account. I'd like to use the MSN calendar as default as it is synced to all my computers when I log on to Outlook. Thanks, Sam Your default calendar folder is always the Calendar folder in your local message store or Exchange Mailbox. You can't make the MSN one the default as far as I know "Sam Crawford" <sam@somewhere.com> wrote in message news:eN531ASxFHA.612@T...

isv.config file
We have altered the isv.config file to show additional tabs and buttons in the CRM forms. These tabs and buttons show and work fine in the web client but are not available to the sales for outlook client. They do not show in Outlook. Should this customisation show in the sales for outlook client? Thanks, Brett if you look in your _resources directory under wwwroot on the crm web server you will see a file called OutlookClient_sample.xml you use this file for the outlook client config file. so you duplicate anything in isv.config to this file and call it i think OutlookClient.config -- ...

Find byte pattern in file (still desperate for solution)
I'm still desperately looking for a solution to this question. I need a very intelligent way to find an array of bytes within a file, but not only that preferably a regex expression of sorts. For example my database has around 50,000 regex entries such as "FFFF.*BB0403.*FF" that I want to turn into a byte array then search for. I understand how to go about writing my own code for this, however it is a little over my head when we're dealing with searching so many patterns against many files while trying to be speedy about the operation. Does anyone have any g...

putting date and time together in 1 cell
Hi I need to convert New Zealand time to UK time, the time is displayed in two parts A B date time dd/mm/yy hh:mm:ss How do i get cell A and cell B into one cell with the format dd/mm/yy hh:mm:ss and then I can just minus 13 hours. any ideas please. =SUM(A2,B2,-13/24) and format the cell as dd/mm/yy hh:mm:ss. HTH Jason Atlanta, GA >-----Original Message----- >Hi I need to convert New Zealand time to UK time, the time >is displayed in two parts >A B >date time >dd/mm/yy hh:mm:ss > >How do i get cell A and c...

Sum based on range values
I need to sum a column A, but only if values in an adjacent column B>0. Therefore the example below should sum to 10 (only including the first 3 rows). A B 7 5 0 4 3 9 0 0 0 0 0 0 8 0 0 0 0 0 Ideally this should be a formula in a cell, not a macro. Any ideas? It doesn't sound complicated, but I can't get my head round it. TIA Ian Thanks Julie. I knew it had to be straightforward. Just a case of knowing which function to use. Ian "JulieD" <JulieD@hctsReMoVeThIs.net.au> wrote in message news:%23$anRGw$EHA.3836@tk2msftngp13.phx.gbl... > Hi > > us...

Renaming Files
I have a great number of files labeled with a first name followed by a last name and a date. I need to switch the file names and save them as Last Name First Name followed by the date? Any suggestion on how to do this? Is there a character which separates the names, like space or underscore? Maybe.... If your file names are 3 parts each separated by a space: John Smith 12022005.xls Something like this might work: Option Explicit Sub testme01() Dim wkbk As Workbook Dim myFileNames As Variant Dim NewFileName As String Dim iCtr As Long Dim lCtr As Long Dim myName A...

How to copy iPhone SMS to TXT file on computer?
[url=http://www.backup-iphone-sms.com/how-to-copy-iphone-sms-to-txt-file.html][b]How to copy iPhone SMS to TXT file with iPhone SMS Backup software on computer?[/b][/url]What is .txt file: .txt is a filename extension for files consisting of text usually contain very little formatting (ex: no bolding or italics). Files with the .txt extension can easily be read or opened by any program that reads text and, for that reason, are considered universal (or platform independent).With Tansee iPhone Transfer SMS, you can [b]backup iPhone SMS to PC as a txt[/b] file and keep them safe. [b]Guide of how ...

Deleting Rows Automatically using a Text File List
I have a text file list of .jpg files that I want to delete (rows) from Excel. The list has 800+ items in it. Deleting these rows one at a time in Excel (after doing a "find") is terribly time consuming. Does anyone know how to make Excel read my text file and delete the rows with that filename in it (automatically). The filename (listed in the text file) is in a column (in my excel sheet) called "filename". Any help would be most appreciated!!! Seriously! I may have to spend hours on this otherwise! Thank you, Arielle -- mirdonamy ------------------------------...

How to change a Macro based on content of a cell
Hi, I need to import a text file into a spreadsheet. I can do this manually by doing File > Open > then select a text file. Then Excel goes through the Text Import Wizard I can automate this by recording a Macro in Excel. The macro looks like this (Excell wrote that for me, I did not): Sub Macro1() Workbooks.OpenText Filename:="C:\DrillData\" + "MOR701.pck", Origin:=xlMSDOS, _ StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1), Array(12 _ , 1), Array(26, 1), Array(37, 1)), TrailingMinusNumbers:=True End Sub How can I change ...

Task Due Dates & SFO
I have found a problem with the due dates and SFO. When I change Task Due Dates in Outlook it DOES NOT change them in CRM. I synchronized, but the Due Dates do not update. On the other hand, when I change the Due Date in CRM it DOES change in Outlook. Is anyone else having this issue? Has anyone solved it? ...

Export Excel file to SQL
I'm currently doing a project where it require client to export excel spreadsheets to SQL. the application that is using the excel spreadsheet exported is a web-based application. Is it possible to do that? Any suggestion or recommendation is greatly appreciated. thank you Go to Enterprise Manager. Browse to your database in the left pane (object browser). Right click your database. All Tasks --> Import Data. Next. Set your datasource to Microsoft Excel 97-2000 or whichever Excel version you have. Click the ... button next to the File Name text box and browse to your Excel sheet. M...

Errors 150 and 382 in browser based client ?
Hello people, We've succesfully set up a MS CRM environment. When I am in the browser based client, everything show Ok. However, as soon as I try to reach whatever menu in the browser, I get an "A runtime erorr has occured. Do you wish to debug ? Line 382. Error: not implemented" error. Sometimes it is an "Line: 150. Error: object doesn't support this property or method" error. I would expect this to be some local security setting in the browser but I've been trying out a couple of settings without success. This message was posted here before already in this ...

sorting by date #2
I am having trouble sorting a table by date. When I choose to sort th column by date - it sorts it alphabetically by date - i.e. with Augus coming first. How can I have Excel sort chronologically, when the date include month, day, yea -- Message posted from http://www.ExcelForum.com It sounds as if the dates are formatted as text. You can change this to an Excel date value by inserting a helper column and using the following formula (assuming your dates are in column A: =DATEVALUE(A1) and copying down. Excel will then recognize the values as date values, not text, and will sort chronol...

Importing a CSV file
I want to import a file into physical inventory. Here is what I do: 1) Run a Quantity report(I don't think the report really matters) 2) I put it in alphabetical order, then I export it using RMS Manager into a ..CSV file 3) I go into Inventory > Physical Inventory, and I click on New and Manuel Entry 4) I import the file...it works just fine!!! BUT If you in any way alter the .CSV file, and save it again, in the same format Steps 1 - 4 won't work...WHY WHAT THE HECK AM I DOING WRONG??? -- Thank You Vince :) The problem might be the Item Lookup Codes are being modified by ...

Theme Files
I am attempting to make a theme file that will work on any computer that I want it to. So far I have made it work on my computer. When opened on other computers it only does some of what I want it to do. Anything anyone could suggest would be great. Themes are not part of Access, they are part of Windows. Your question may be better answered in a newsgroup appropriate to your problem. This newsgroup is dedicated to the Microsoft Access database product. -- Arvin Meyer, MCP, MVP http://www.datastrat.com http://www.mvps.org/access http://www.accessmvp.com "Nathan Ri...

Outlook Express creates a File on my desktop
ok i dont know if anyone else is getting this problem but when ever i run outlook express it creates a file on my desktop named "~". it has done this since new, and ive seen it on one other computer as well. is there a way to stop this from happening?? cause deleting the file everytime is getting tiresome...if anyone knows how to fix this please let me know. ty Shawn <anonymous@discussions.microsoft.com> wrote: > ok i dont know if anyone else is getting this problem but > when ever i run outlook express it creates a file on my > desktop named "~". ...

Calculating days and dates
I need to calculate the number of working days (ie Monday to Friday) from the date entered in cell D4 (22/07/2005). This needs to update each day in cell E4. I can do this not based on working days, by entering =DATEDIF(D4,TODAY(),"d") but where in the formula do I reference it to working days or network days? HELP! -- HDV ------------------------------------------------------------------------ HDV's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=26299 View this thread: http://www.excelforum.com/showthread.php?threadid=395788 You can use the ...

Excel 2003, Opening a file
Hello Everyone, I have this problem when trying to open a file in Excel. It takes along time to drill down down in the folder list. Any ideas? Thanks -Mark I suggest putting a shortcut to the file(s) or to the buried folder that your file(s) are in. The shortcut could be on your desktop or in some folder close to the "surface". To create the shortcut or your desktop you can navigate to the desired folder (using My Computer), right click and drag the folder to your desktop. When you release respond that you want to create a shortcut (rather than moving or copying...

Deleting Files
Was treasurer for an organization; term has ended; want to delete that file entirely; can find no way to do it. I would appreciate any help in that area. TY -- HerbFry Go find the file and delete it. I'm probably missing something here like what "can find no way to do it" means. How do you delete Word files? Excel files? Notepad files? "HerbFry" <HerbFry@discussions.microsoft.com> wrote in message news:3A841D96-66F5-4734-84A8-F5634FC09272@microsoft.com... > Was treasurer for an organization; term has ended; want to delete that > file > entirely...

can't save files in subfolders using Word #2
I'm running Word on a Mac running OS X. When I go to save a file in Word, it only gives me the option to save in the root files like "Documents" or "Applications." How do I save the file into a subfolder? On a PC, I would double click to open the folders until I got to the folder I needed. That doesn't work here. Can someone help? I'm sure this is something obvious I'm missing. Thanks - Taylor In article <1163740041.258317.226140@b28g2000cwb.googlegroups.com>, taylorgriffin@gmail.com wrote: > I'm sure this is something obvious I'...

Database File Size
Hello All, A quick question regarding the Database size: We had an old Access database file protected by Security Wizard, We created a new database file and import everything from the old file, however the size is not exactly the same, the new database file is way smaller than the old one. Does that mean any data lost in the import process? Or is there any other reason such as we used the Security Wizard on the old one not the new one so that overhead was added...anyone could explain this? Also is there a way to compare the two database file to see if they are the same or not? Thanks a lot!...

using find and replace it's making me look in another file to upd
I have used the find and replace function several times in the spreadsheet to update the fromulas monthly. For some reason when I use it this month it wants me to look in another file to "update values"? There is not another file and there is no way for me to use the find and replace. ...

Passing node-sets as parameters?
I essentially need a countif() function for xsl. Something to where I could do countif(node-set, condition). Rather than try to get too extreme, i decided to just write one for my countif() with the condition hardcoded. (this was also my first venture into creating "functions") Pseudo-code is essentially this: Look at the current node and check the condition. If the condition is true, call our function again with an incremented count. If false, call function with the same value. Once we reach the end of the node set, return the counter variable. The whole time we're passin...

Publisher 2007 file is listed on my network, but the file wont ope
After designing a publisher application with Microsoft Office 2007, I have saved the document to my local network, and ALAS, the folder containing the file is "empty", but clicking on the folder shows the document(properties, size etc.) but I cannot open/edit/rename the file! Any help is greatly appreciated. Can you open the file if you drag it to your local hard drive? -- Mary Sauer http://msauer.mvps.org/ "jtjordan_design" <jtjordan_design@discussions.microsoft.com> wrote in message news:9BBA993D-09AE-4BE5-BEFC-0A06705A16D0@microsoft.com... > After desi...