0

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 :)

Danielx64
  • 3
  • 2

3 Answers3

1

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.

Snak3d0c
  • 626
  • 4
  • 11
  • Thank you for that, and I was wondering if I was looking at the right docs :) So will this work? `get-childItem C:\temp\pos\mail\* -Recurse | rename-item -newname { $_.name -replace '$','.eml' }` Because there is no extension on the end of any file at all. – Danielx64 Sep 27 '17 at 08:34
0

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?

Snak3d0c
  • 626
  • 4
  • 11
  • I know that mailstore will be able to import .eml files and I can open eml files directly in outlook so I know that part will work. It just the renaming that I need to get sorted out. I'm taking a look at https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-childitem?view=powershell-5.1 right now Thank you for your feedback :) – Danielx64 Sep 27 '17 at 08:02
  • I know outlook can open EML files, the reason for me asking is, i'm wondering if the structure of your files is that similar that you can just rename it to EML and that it would work. – Snak3d0c Sep 27 '17 at 08:19
0

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" }
Vincent K
  • 1,326
  • 12
  • 19