A more complicated, but generic way would be to use a regular expression which extracts the trailing number of the path you are processing:
$folders = @("C:\temp\test1", "C:\temp\test12", "C:\temp\test123", "C:\temp\t35t1234")
$regex = [Regex]'(?< Name >.*\w[^0-9]+?)(?< Index >\d+)$' # Remove the spaces in the angle brackets
foreach ($folder in $folders)
{
if ($folder -match $regex)
{
$Matches["Name"]
[Int32]$Matches["Index"]
}
}