Adding .eml to the end of every filename in multiple folders

365 views Asked by At

So here's the deal:

I been using Thunderbird - it been great but I want to move to Microsoft Outlook. Now because I taken things a little too far, I decided to use maildir for storing my emails. Again it was wonderful but I need to move on.

My plan was to do Thunderbird ->import into mailstore ->export to pst -> import into outlook (or get outlook to open the file).

Now that should be easy enough but the issue is that I need a way to add the ".eml" to the end of every file otherwise mailstore won't import the emails.

I'm running Windows 10 pro x64 and this is what I am doing in powershell:

Get-ChildItem -File -Recurse | % { Rename-Item -Path $_.PSPath -NewName $_.FullName ( $_.Name + ".eml" )}

Now I saw the answer given in https://stackoverflow.com/a/21611922/1129151 but it wasn't what I was after. I also saw http://www.kevinberridge.com/2010/06/powershell-add-extension-to-every-file.html but the issue was that it didn't handle adding the ".eml" recursively.

When I tried to run the above code I get

Rename-Item : A positional parameter cannot be found that accepts argument '1506493412587000.eml'. At line:1 char:36 + ... curse | % { Rename-Item -Path $.PSPath -NewName $.FullName ( $_.Nam ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Rename-Item], ParameterBindingException + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.RenameItemCommand

Could someone please tell me what I need to do to get the ".eml" on?

Thank you :)

3

There are 3 answers

1
Vincent K On BEST ANSWER

So all files have no extension. I have added File parameter which will only retrieve files and not folder, use it if you have any sub folders in your mail folder.

get-childItem C:\temp\pos\mail\*.* -Recurse -File | rename-item -newname { "$($_.name).eml" }
2
Snak3d0c On

You should have a look at the help of get-childitem.

Look at the examples and more in particular, example number 4.

EDIT:

Before you do this to all your files, have you done one manually and checked if it works in Outlook?

1
Snak3d0c On

So it seems that i have mislead you to the wrong help section, for that i'm sorry. I should have lead you to the help of rename-item. (sorry busy at work).

So there you would find:

 get-childItem *.txt | rename-item -newname { $_.name -replace '\.txt$','.log' }

That should get you going, for example:

get-childItem C:\temp\pos\mail\*.* -Recurse | rename-item -newname { $_.name -replace '\.txt$','.eml' }

You should change the txt into the extension your files have.

Notice the \ and $ in the replace part? That's a regular expression. The \ is to say, look for an actual dot. The $-sign is to say, at the end of the string.