I have a series of folders in a source directory that I need to recreate in another environment. The source folder look like this:
C:\temp\stuff\folder01\
C:\temp\stuff\folder02\
C:\temp\stuff\folder03\
C:\temp\stuff\folder02\dog
C:\temp\stuff\folder02\cat
I need to remove the base portion of the path - C:\temp\stuff
- and grab the rest of t he path to concatenate with the destination base folder in order to create the folder structure somewhere else.
I have following script. The problem seems to be with the variable $DIR
. $DIR
never gets assigned the expected "current path minus the base path".
The variable $tmp
is assigned something close to the expected folder name. It contains the folder name minus vowels, is split across multiple lines, and includes a bunch of leading whitespace. For example, a folder named folder01
would look like the following:
f
ld
r01
Here's the PowerShell script:
$SOURCES_PATH = "C:\temp\stuff"
$DESTINATION_PATH = "/output001"
Get-ChildItem "$SOURCES_PATH" -Recurse -Directory |
Foreach-Object {
$tmp = $_.FullName.split("$SOURCES_PATH/")
$DIR = $_.FullName.split("$SOURCES_PATH/")[1]
$destination = "$DESTINATION_PATH/$DIR"
*** code omitted ***
}
I suspect the $DIR
appears to be unassigned because the [1] element is whitespace but I'm don't know why there is whitespace and what's happening to the folder name.
What's going on and how do I fix this?