Renaming Files Across Different Folders


Recommended Posts

Over the years, I have amassed several 1000s of photos that I have backed up from my iPhone. If memory serves me correctly iOS names them IMG_0001.jpg, IMG_0002.jpg, IMG_0003.jpg etc etc. Now, whenever I have updated my iOS I have always started afresh without restoring from backup. So, I would manually copy my photos over to my PC. This would mean that iOS would name my pictures starting from IMG_0001.jpg again. I have several 1000s of photos in folders across a folder struct like below:

C:\Other Files\Photos...
\2010
\2011
\2012
\2013
\2014

I'd like to get these images all in to one folder "C:\Other Files\Photos"

Would it be possible to do a script that would take the photos in folder 2010 and assuming there were 567 photos in that folder rename them to "0001.jpg", "0002.jpg" ... "0567.jpg" and then move on to 2011 and start from "0568.jpg" and so on for the whole folder structure? This is so that I can have all my photos in one folder, without fear of overwriting duplicates and so that I can copy them back to my iPhone Camera Roll and have them in dated order, with the newly taken photos starting at the end of the camera roll after the older ones.

Link to comment
Share on other sites

im sure this is possible, but im no programmer. more pressing, though, is wouldnt you want to keep them in a year format instead of just a number? dont you want to remember when that particular photo was taken?

 

are these just random photos? i like to organize mine into a particular event like 'someone's wedding' or 'whatever vacation'.

Link to comment
Share on other sites

im sure this is possible, but im no programmer. more pressing, though, is wouldnt you want to keep them in a year format instead of just a number? dont you want to remember when that particular photo was taken?

 

are these just random photos? i like to organize mine into a particular event like 'someone's wedding' or 'whatever vacation'.

They're just random photos I've taken on a day to day basis. Nothing is organised in an event. The reason I want to rename the files is because I want them all in my camera roll. Just one big camera roll.

Link to comment
Share on other sites

You could do this in powershell:

 

$count = [int]0;dir -recurse C:\Other Files\Photos *.jpg | foreach-object {Copy-Item -Path $_.FullName -Destination "c:\temp\$($count.ToString() + '.jpg')"; $count++}

  • Like 2
Link to comment
Share on other sites

They're just random photos I've taken on a day to day basis. Nothing is organised in an event. The reason I want to rename the files is because I want them all in my camera roll. Just one big camera roll.

 

Right, but wouldn't you want say '2011_0001.jpg' instead of just '0001.jpg'?

Link to comment
Share on other sites

Right, but wouldn't you want say '2011_0001.jpg' instead of just '0001.jpg'?

That sounds like a good idea.

 

You could do this in powershell:

 

$count = [int]0;dir -recurse C:\Other Files\Photos *.jpg | foreach-object {Copy-Item -Path $_.FullName -Destination "c:\temp\$($count.ToString() + '.jpg')"; $count++}

Thanks, I'll give that a try and see how it goes! Bit of a n00b question. But how do I run a PS script in a batch file? I know with batch scripts it's .bat and double click, but how do I do that with PowerShell?

Link to comment
Share on other sites

That sounds like a good idea.

 

Thanks, I'll give that a try and see how it goes! Bit of a n00b question. But how do I run a PS script in a batch file? I know with batch scripts it's .bat and double click, but how do I do that with PowerShell?

 

Use ".ps1" for the file extension.

Link to comment
Share on other sites

The PowerShell solution looks pretty good, I will abandon my AutoIT efforts.

 

PowerShell looks very interesting. I really must learn about it.

You know of any decent online tutorials/reference I can use? Thanks.

Link to comment
Share on other sites

The PowerShell solution looks pretty good, I will abandon my AutoIT efforts.

 

PowerShell looks very interesting. I really must learn about it.

You know of any decent online tutorials/reference I can use? Thanks.

 

Whenever I write a shell script, I'm usually always trying to do something specific rather than just learn for the sake of learning, and I've found that web searches are generally very helpful with examples. It's not uncommon that results from this blog pop up:

 

http://blogs.technet.com/b/heyscriptingguy/

 

Also, Powershell itself includes a pretty comprehensive manual (type get-help <COMMAND> or use the man alias).

Link to comment
Share on other sites

I tried running the PowerShell command and I got this error:

Get-ChildItem : A positional parameter cannot be found that accepts argument '*.jpg'.
At line:1 char:20
+ $count = [int]0;dir <<<<  -recurse C:\Other Files\Photos *.jpg | foreach-object {Copy-Item -Path $_.FullName -Destination "c:\temp\$($count.ToString() + '.jpg')"; $count++}
    + CategoryInfo          : InvalidArgument: (:) [Get-ChildItem], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

Any ideas?

 

EDIT: Found the problem. It was caused by missing quotes around "C:\Other Files\Photos"

 

That script copied the photos to C:\Temp, but it renamed the files "1.jpg", "2.jpg", "3.jpg" etc. Is there anyway I can get the numbering to "0001.jpg", "0002.jpg", "0003.jpg" etc.

Link to comment
Share on other sites

You've probably sorted this by now, but some time ago there was a tool listed on here https://twitter.com/sourceforge which I used very successfully. Problem is, I can't remember the name of it now :(

 

This might be useful too

 

http://sourceforge.net/directory/system/storage/file-management/os:windows/freshness:recently-updated/

Link to comment
Share on other sites

That script copied the photos to C:\Temp, but it renamed the files "1.jpg", "2.jpg", "3.jpg" etc. Is there anyway I can get the numbering to "0001.jpg", "0002.jpg", "0003.jpg" etc.

 

$count = [int]0;dir -recurse C:\src\tmp *.jpg | foreach-object {Copy-Item -Path $_.FullName -Destination "c:\src\out\$($count.ToString().PadLeft(4, '0') + '.jpg')"; $count++} 
Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.