Tuesday, April 7, 2015

How To Extract Pattern from a folder path (VBA Excel)

I'm pretty new to vba excel and trying to reorganise a very large file structure. Basically, all our equipment has a tag in the form of [A-Z][0-9]0-9][0-9][A-Z] e.g. J452G being a compressor. Every equipment has a folder with its name on (e.g. "C:\Users\Ron\Documents\J452G" consist of drawings, subfolders, excels, pdfs,..). The problem is that I would like to copy this equipment folders to a new directory such that all equipment tags have a folder within one single directory (to make alphabetical searching easy). Now these folders are distributed in a tree-like folder structure with lots of subfolders.


What I would like to do is



  1. Extract the file paths (e.g. "C:\Users\Ron\Documents\J452G") 'This I already managed to do

  2. Look for the pattern [A-Z][0-9]0-9][0-9][A-Z] and copy all files and subfolders to a new directory with the name of the equipment.


Result should be a main folder (e.g. C:\Users\Ron\Documents) containing a folder for every equipment tag with the corresponding documents enclosed.


I'm particularly stuck on how to extract the pattern [A-Z][0-9]0-9][0-9][A-Z] from a string if found and assigning is to the Destination:=


e.g. C:\Users\Ron\Documents\Nieuwe map \iets\Drogers\F941E\
copy content and subfolders to C:\Users\Ron\Documents\F941E\


Many thanks in advance!

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...