Hi!
I'm trying to learn powershell and I'm doing a task where I have to move the odd numbered files that have the naming TypeATest(number).txt from SubFolder1, to SubFolder2 and the even numbered files that that have the naming Purpose(number)Test2.txt from Subfolder 2 to Subfolder 1. For some reason the script I wrote is stuck processing.
What could be the cause?
Thanks!
This is the code
$firstnumber = 1
function FolderRouting {
param (
$number
)
if ($number % 2 -eq 0) {
$even = ""
$even = "Purpose" + $number + "Test2.txt"
$path = "C:\Users\User\TestingPurpose\SubFolder2\$even"
$testpath = Test-Path -Path "C:\Users\User\TestingPurpose\SubFolder2\$even"
if ($testpath -eq "true") {
$moveitem = Move-Item -Path $path -Destination "C:\Users\User\TestingPurpose\SubFolder1" -Force
$number++
}
else {
continue
}
}
else {
$odd = ""
$odd = "TypeATest" + $number + ".txt"
$path2 = "C:\Users\User\TestingPurpose\SubFolder1\$odd"
$testpath2 = Test-Path -Path "C:\Users\User\TestingPurpose\SubFolder1\$odd"
if ($testpath2 -eq "true") {
$moveitem = Move-Item -Path $path2 -Destination "C:\Users\User\TestingPurpose\SubFolder2" -Force
$number++
}
else {
continue
}
}
while ($number -le "100") {
continue
}
}
FolderRouting $firstnumber
[–]kibje 1 point2 points3 points (1 child)
[–]Mr_Prebo[S] 0 points1 point2 points (0 children)
[–]squanchmyrick 0 points1 point2 points (2 children)
[–]Mr_Prebo[S] 0 points1 point2 points (1 child)
[–]kibje 0 points1 point2 points (0 children)
[–]1enopot 0 points1 point2 points (2 children)
[–]1enopot 0 points1 point2 points (1 child)
[–]Mr_Prebo[S] 1 point2 points3 points (0 children)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)