그래서 약 1200 곡의 디렉토리를 통해 빗 스크립트, 사용자는 (다음 $Selected
변수에 투입)하고 "스크립트 마법"(I를 통해 한 곡을 선택해야 필요한 경우 코드를 제공 할 수 있습니다,하지만 난 그것을 이메일은 내가가 전송해야 할 이메일 계정으로 전송되는) 우리의 목적을위한 것입니다 생각하지 않습니다. 내가 문제로 실행하면 즉 aaaannnnndddd 나는 다음 디렉토리에서 노래를 삭제할.제거 품목 cmdlet을 제대로
Remove-Item C:\Users\woafr\Desktop\Songs\$Selected -recurse -force
그리고 그 코드와 나는이 오류 메시지와 함께 맞았 : 여기에 내가 처음으로 노래를 삭제하려고했습니다 코드가
Remove-Item : Cannot remove item C:\Users\woafr\Desktop\Songs\song.mp3: The process cannot access the file C:\Users\woafr\Desktop\Songs\song.mp3' because it is being used by another process
그래서 나는 다음 읽기 this artice 및 this Stack Overflow threadthis Server Fault thread으로 변경하고 내 코드를 다음으로 수정했습니다.
Get-ChildItem C:\Users\woafr\Desktop\Songs\$Selected -recurse -force | Remove-Item
그리고 여전히 같은 오류가 발생했습니다. 내가 노래를 삭제해야합니다 내가 여기서 할 수있는 일이 있습니까, 아니면 손으로해야 할 것 여기
# Search Engine part
$SearchInput = Read-Host "Enter song name here:"
$Items = Get-ChildItem C:\Users\woafr\Desktop\Songs -Recurse -Filter *$SearchInput*
IF (-Not $Items)
{Write-Host 'Nothing returned...
The search engine does not care about capitilization (so "That" and "that" are read the exact same by the search engine)
But it does care about punctuation (so "That''s" and "Thats" are not read the same by the search engine). Try Again' -ForegroundColor Red}
# Choose you this day what song you want
IF (-Not $Items)
{cmd /c pause}
$Index = 1
$Count = $Items.Count
foreach ($Item in $Items) {
$Item | Add-Member -MemberType NoteProperty -Name "Index" -Value $Index
$Index++
}
$Items | Select-Object Index, Attributes, LastWriteTime, Name | Out-Host
$Input = Read-Host "Select an item by index number, then press enter (1 to $Count)"
$Selected = $Items[$Input - 1]
Write-Host "You have selected $Selected"
# Email account the script is sending from
$SMTPServer = "smtp.gmail.com"
$SMTPPort = "587"
$Username = "[email protected]"
$Password = "mypassword"
# Email the script is sending
$to = "[email protected]"
$subject = "Songs To Ingest"
$body = "Ingest attachment into WideOrbit"
$attachment = New-Object System.Net.Mail.Attachment("C:\Users\woafr\Desktop\Songs\$Selected")
$attachment.ContentDisposition.FileName = "$Selected"
# Act of sending the email
$message = New-Object System.Net.Mail.MailMessage
$message.subject = $subject
$message.body = $body
$message.to.add($to)
$message.from = $username
$message.attachments.add($attachment)
$smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort);
$smtp.EnableSSL = $true
$smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
$smtp.send($message)
write-host "Mail Sent" -ForegroundColor Green
cmd /c pause
# Trying to delete the damn thing
Get-ChildItem C:\Users\woafr\Desktop\Songs\$Selected -recurse -force | Remove-Item
cmd /c pause
마술 스크립트를 제공 할 수 있습니까? –
@Flynn HANDLEY 그래, 하하. 그냥 내가 당신의 -force 파이프의 왼쪽에 발견 –
위의 편집, 나는 당신이 -recurse를 읽고 있도록이 오른쪽에있을 수도 있습니다 생각 | 제거-항목 그렇지 않으면 당신은 Get-내용, 그리고 Remove-Item cmdlet을 강제하려는 -force. – Random206