Quantcast
Channel: PowerShell General
Viewing all articles
Browse latest Browse all 10624

Moving filders with a hyphen in name to parent folder with similar name

$
0
0

I am looking to write a script that will move existing folders with a "-" hyphen in the name into a parent folder with part of the same name.

Example:

I would like to move c:\12345-01 into c:\12345\ to look like this c:\12345\12345-01.

The problem is the number of characters before the hyphen is not the same and it may have letters (12345abc-01). They very from 3-9 characters before the hyphen. I have found a couple of snipets here and elsewhere that are close, but they won't work as they specify the number of characters in the file name

For Each objFile in objFolder.Files strName = Left(objFile.Name, 3) this would work if all filenames were 3 characters.

Does that makes sense?


Viewing all articles
Browse latest Browse all 10624