0

How can I copy all .msg files that are spread throughout some GUID sub-folders in one folder to another folder that has a slightly different folder name at the end. Is it possible?

So for example:

  • Source
  • c:\Folder A\16-1167 Contoso 1 Hacker Way\Correspondence
  • c:\Folder A\16-1168 Company name, address\Correspondence
  • Destination:
  • C:\Folder B\16-1167\0ba45cbd-6da8-4a4c-ae1c-9aca13aab1db\1\filename.msg
  • C:\Folder B\16-1167\971d6bd3-d4f0-478d-b12d-ba0f9f1ea088\1\random filename.msg
  • c:\Folder B\16-1168\971d6bd3-d4f0-478d-b12d\1\email.msg etc

I want to use a program or a script to copy all the *.msg into one folder in the source. It's complicated by the fact that the source has a job name after the job number. So the first 7 characters of the folder name are identical but the ending isn't.

Damian
  • 1
  • Yes, this is certainly possible by using regular expression to extract desired part of the path to a variable. In Windows, you could use PowerShell to write such a script. – Tero Kilkanen Oct 05 '21 at 05:26
  • can you give an example? – Damian Oct 05 '21 at 06:08
  • This site is not a script writing service. You should try writing the script yourself, and if you cannot get it to work, then ask for help here why it doesn't work. – Tero Kilkanen Oct 05 '21 at 17:40
  • I guess you don't really know what you are talking about then. – Damian Oct 06 '21 at 03:08
  • https://pastebin.com/tJE1WAy9 Kind of got it working but it doesn't copy the .msg files from each job folder to the job folder, it dumps every msg into the root of A. Can anyone offer a solution? – Damian Oct 06 '21 at 04:40
  • https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_regular_expressions?view=powershell-7.1 explains how to use regular expression in PowerShell. You need to capture part of the string and use that part in the destination. – Tero Kilkanen Oct 06 '21 at 06:28
  • Thanks for the tip. – Damian Oct 06 '21 at 23:08

0 Answers0