[ad_1]
What’s wrong with this code?
If the path is in the same drive as powershell script is it works even with spaces in the path
If the path is in a different drive it does not work if there are spaces in the path. If there are no spaces it works.
Script has a path passed as a first argument.
$param1=$args[0]
write-host "Given path is: " $param1
$rootPath = "$param1"
Get-ChildItem -Path "$rootPath" -Include RARBG.txt,RARBG_DO_NOT_MIRROR.exe -File -Recurse | foreach { $_.Delete()}
Get-ChildItem -Path "$rootPath" -Directory | ForEach-Object {
$_.FullName
$targetFolder = $_.FullName
$targetFolder
Get-ChildItem $targetFolder\*English*.srt | Move-Item -Destination $rootPath
}
Get-ChildItem -Path "$rootPath\" -Directory -Filter "Subs" | Remove-Item -Recurse -Confirm:$false -force
PAUSE
error code
Given path is: H:\@Movies - not seen\Forrest.Gump.1994.REMASTERED.1080p.BluRay.x265-RARBG"
Get-ChildItem : Illegal characters in path.
At E:\downloads\@torrents\movies-remove-moveAndRemoveSubs-folder.ps1:6 char:1
+ Get-ChildItem -Path "$rootPath" -Include RARBG.txt,RARBG_DO_NOT_MIRRO ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (H:\@Movies - no...Ray.x265-RARBG":String) [Get-ChildItem], ArgumentExc
eption
+ FullyQualifiedErrorId : ItemExistsArgumentError,Microsoft.PowerShell.Commands.GetChildItemCommand
Get-ChildItem : Cannot find path 'H:\@Movies - not seen\Forrest.Gump.1994.REMASTERED.1080p.BluRay.x265-RARBG"' because
it does not exist.
At E:\downloads\@torrents\movies-remove-moveAndRemoveSubs-folder.ps1:6 char:1
+ Get-ChildItem -Path "$rootPath" -Include RARBG.txt,RARBG_DO_NOT_MIRRO ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (H:\@Movies - no...Ray.x265-RARBG":String) [Get-ChildItem], ItemNotFound
Exception
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
[ad_2]