How to extract emails from a list of folders where the email is into the folder name in windows?
I have a list of folders that has those names variations: (there are around 700 folders, so manually is not an option)
name name name - email@email.com
name name name - email@e开发者_Go百科mail.com + email@email.com + email@email.com + email@email.com
take care about this: between the name and the email always exists:
" - "
between emails, when exists always exists:
" + "
I would like to take the
"name name name" and assign all the emails for each name in an excel sheet.
I think I need a batch to loop all folders, get the folder name, extract the name, extract the emails and write down in a text file. For repeted email I would like to have a another row, so each name has a single email. The names might be repeated but they refer to different emails.
Then from the text file I have to convert to a excel file.
Thanks for your help
Run these two command from the commandline in the directory where your direxctory tre starts.
for /D %a in (*.*) do @echo %a >> dlist.txt
for /F "tokens=1,2* delims=-" %a in (dlist.txt) do @echo "%a" ; "%b" >> emails.csv
In VBA for the Excel paste this:
Option Explicit
Sub GetFileNames()
Dim i As Integer
Dim fso As Object, folder As Object, subfolder As Object
i = 0
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder("C:\Users\****\Desktop\****")
For Each subfolder In folder.SubFolders
ActiveCell.Offset(i) = subfolder.Name
i = i + 1
Next subfolder
End Sub
- Select the first col, first row
- Then click run, to run the VBA command
- This will create all the rows with the name of the folders
- Then in the B, use this formula: "=LOCALIZAR(" - ";A2)"
- In C: "=NÚM.CARACT(A2)"
- In D: "=SEG.TEXTO(A2;1;B2)"
- In E: "=SEG.TEXTO(A2;B2 + 3;C2)"
- In F: "=SUBST(E2;" + ";", ")"
In D you will get the name, and in F you will get all the emails separated by ", ". That's all!
精彩评论