0

Short story: saved pictures from phone to computer, preserved last modified date, destroyed created date. So in wanting to restore them to the phone, and preserve the order in which they were made in the phone, I searched for a means to make the created date the modified date:

(get-item "picture.jpg").CreationTime = (get-item "picture.jpg").LastWriteTime

Not wanting to write a line for each of the several thousand pictures in a few dozen folders, expanded it to this first to test on a single folder:

Get-ChildItem | ForEach-Object { ($_.CreationTime) = ($_.LastWriteTime) }

And ran this with PS in test folder.

So to avoid having to run this command in each folder, I would be doing this:

Get-ChildItem -recurse | ForEach-Object { ($_.CreationTime) = ($_.LastWriteTime) }

And running that in the root folder of the saved pictures. It worked as expected.

But before I royally mess up, is my syntax correct or will I do something really catastrophic to my system or is there a better way of doing this?

P.S. While I am a computer programmer, at times I'm not good with finding the right information I need to complete a task because I'm not searching for the correct terms.


Based on the comments so far:

Get-ChildItem "[**redacted**]Phone\Pictures\" -File -Recurse | ForEach-Object { $_.CreationTime = $_.LastWriteTime }

3
  • 4
    Without specifying switch -File your code will also affect directories. Maybe you don't want that? Commented Jul 8 at 19:25
  • 4
    Also target the path where the pictures are in: Get-ChildItem the\path\toThePictures -Recurse ... Commented Jul 8 at 19:29
  • 3
    As an aside: you don't need (...) around the operands of your assignment statements. Commented Jul 8 at 20:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.