4

On my Android phone, it was configured to save pictures to the Phone-memory.

I wanted to free up some memory in the phone, and since I have a 16GB uSD card, I:

1) copied all the pictures to my computer using the USB cable.
2) erased the picture files (and thumbnails) from the phone memory.
3) configured the phone to save pictures to the uSD card.
4) copied all the pictures from the computer to the uSD card on the phone.

All is working now, except that the timestamp (and sort-order) for all the pictures on the phone (uSD) are now all screwed up ... showing the date/time that I performed the copy operation.

Fortunately, the timestamps for the pictures on the computer are all correct.

I was thinking to write a script using PowerShell (or a combination of Batch/PowerShell) to:
1) for each picture file that exists in both the phone and computer...
2) read the timestamps (creation and modification) from the file on the computer
3) set the timestamps for the file on the phone memory card

The paths are something like:
Phone: "K:\DCIM\100Media"
Computer: "F:\Android\SDCard\DCIM\100Media"

What I have found so far about PowerShell, I could do:

$timestampw = (Get-ChildItem 'F:\Android\SDCard\DCIM\100Media\file1.jpg').LastWriteTime
$timestampc = (Get-ChildItem 'F:\Android\SDCard\DCIM\100Media\file1.jpg').CreationTime

(Get-ChildItem 'K:\DCIM\100Media\file1.jpg').LastWriteTime = $timestampw
(Get-ChildItem 'K:\DCIM\100Media\file1.jpg').CreationTime = $timestampc

I still need info about:
1) unclear determining when I should use "Get-ChildItem" vs. "Get-Item"
2) check if the file exists on the phone.
3) how to pass the paths / filenames to the PowerShell script.
4) how to refer to the command line arguments within the PowerShell script.

I could also use this in PowerShell to loop through all the files on the computer:  
$files = Get-ChildItem 'F:\Android\SDCard\DCIM\100Media'  
ForEach ($file in $files) ...  

5) how to wrap all this up and create a PowerShell script file

As an alternative to doing this entirely in PowerShell, I could write a batch file to call PowerShell (command-line) twice for each file:

@echo off

set "sp=F:\Android\SDCard\DCIM\100Media"
set "dp=K:\DCIM\100Media"
cd "%sp%"
cd "%dp%"
F:

for %%f in ("*.jpg") do call :work "%%f"
goto :EOF

:work
set fn=%~1
set "ss=%sp%\%fn%"
set "ds=%dp%\%fn%"

if not exist "%ds%" goto :EOF

call PowerShell ... 'copy LastWriteTime from "%ss%" to "%ds%"
call PowerShell ... 'copy CreationTime from "%ss%" to "%ds%"
goto :EOF

For that to work, I just need to know how to compose the command-lines to call PowerShell.

Obviously the Batch/PowerShell method would be easier to complete, but for further understanding of PowerShell, it would be great to see both.

Also, is it possible to read the creation timestamp from the picture file meta-data using PowerShell ?

Thanks to all who can provide some help.

1 Answer 1

3

I'm sure everything you want can be done with PowerShell. What I want to know is, do you absolutely need to use PowerShell or will command-line utils that you can invoke from a batch file do?

For example, to set the time stamp for images to what is stored in their Exif headers, just specify:

jhead -ft *.jpg (Command-line options detailed here)

To copy any file's last modified/accessed time stamp to another, you can use:

touch -r SourceFile DestFile (This version of Touch is part of the GNU Utilities for Win32)

To copy any file's last created/modified/accessed time stamp to another, you can use:

touch /c /m /a /r SourceFile DestFile (This version of Touch is part of the Win32 Console ToolBox)

Note: All three utilities can be downloaded via the links above.

5
  • Thanks for link to "jhead". It looks like it will do the trick, but I haven't tried it yet. The two versions of touch.exe (plus filetouch.exe) that I have on my computer (Win-7-x64) do not allow timestamp to be taken from the timestamp of a secondary file. I'll try to find one that does. PowerShell is not totally necessary to resolve this, but as I mentioned in my post, I am interested in developing further understanding of PowerShell. Oct 29, 2012 at 0:12
  • "I'll try to find one that does." - I already linked to two above, so you don't need to waste any time finding them! :) As for PS, I'm no expert so won't hazard a half-baked answer.
    – Karan
    Oct 29, 2012 at 0:30
  • Sorry, I didn't notice the links at the beginning of each of your examples... I only saw the "here" link at the end of "jhead" line. I've given you an upvote for all your great help. I thought that one of the versions of touch on my computer that does not allow timestamp to be taken from the timestamp of a secondary file was from "unxutils", but I'll have to verify that. Oct 29, 2012 at 1:19
  • 1
    Added a note to my answer to clarify that those are links. Also, for EXIF-related PS modules/code, check here and here.
    – Karan
    Oct 29, 2012 at 1:28
  • For some reason UnxUtils.zip isn't available at the original site. Luckily it can be downloaded from the web-archive - web.archive.org/web/20061017043747/http://…
    – AntonK
    Feb 20, 2017 at 20:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .