What I want: I want to create new directories as per certain requirements (written in my script) and move all DFF files to the newly created folder. Here’s my script:
My code:
function GetDiscLocation($parentFolder, $discNumber) {
$discLocation = $parentFolder
if ($DiscNumber -gt 0) {
$subDirectoryPath = $parentFolder + "/" + "Disc $discNumber"
New-Item -ItemType Directory -Path $subDirectoryPath -Force
$discLocation = $subDirectoryPath
}
return [string]$discLocation
}
And how I am using it:
#Create Directory to Move DFF Files
$discLocation = GetDiscLocation $stereoParentFolder $discNumber
Write-Output "Disc Location: $($discLocation)"
if (Test-Path $discLocation) {
"Successfully created: $($discLocation)"
}
#Move DFF to New Folder
Get-ChildItem -Recurse *.dff | % { Move-Item $_.FullName $discLocation }
I get an error of trying to pass an array even though I have explictly set the return type to string:
PS C:\Users\Lance\Desktop\SACD\Done\Mozart - Violin Concertos, Julia Fischer> extractSACDs
Disc Location: C:\Users\Lance\Desktop\SACD\Done\Mozart - Violin Concertos, Julia Fischer [SACD - 2.0 - 24-88.1]\Disc 1 C:\Users\Lance\Desktop\SACD\Done\Mozart - Violin Concertos, Julia Fischer [SACD - 2.0 - 24-88.1]/Disc 1
Successfully created: C:\Users\Lance\Desktop\SACD\Done\Mozart - Violin Concertos, Julia Fischer [SACD - 2.0 - 24-88.1]\Disc 1 C:\Users\Lance\Desktop\SACD\Done\Mozart - Violin Concertos, Julia Fischer [SACD - 2.0 - 24-88.1]/Disc 1
Move-Item: C:\Users\Lance\Documents\PowerShell\SACD.ps1:67
Line |
67 | … -ChildItem -Recurse *.dff | % { Move-Item $_.FullName $discLocation }
| ~~~~~~~~~~~~~
| Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'Destination'. Specified
| method is not supported.
What am I doing wrong? Also why is the newly located directory name the same folder twice instead of just once?
C:\Users\Lance\Desktop\SACD\Done\Mozart - Violin Concertos, Julia Fischer [SACD - 2.0 - 24-88.1]\Disc 1 C:\Users\Lance\Desktop\SACD\Done\Mozart - Violin Concertos, Julia Fischer [SACD - 2.0 - 24-88.1]/Disc 1