- Apr 9, 2016
- 1
- 0
- 0
I have the beginnings of a script I need to copy all the songs I want to add to my phone to a certain directory so I can copy them to my phones SD card. (It seems media player does not copy the files properly as they will not play on my phone if I copy them through media player.) I would like to be able to check the file names that are on the phones SD card and compare them to the list of files in my Phone music folder on my hard drive. So that I either only try to copy the files that do not already exist on the phone or skip the files that are already there. So far I have the following parts that work as far as copying the song files into the directory I choose except I am not sure how to use the folder browser function as I just found that function and have not finished creating it fully.
Code:
cls
Function Get-FileName($PlaylistDirectory)
{
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
}
Add-Type -AssemblyName System.Windows.Forms
$FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog -Property @{
SelectedPath = 'C:\Temp
}
[void]$FolderBrowser.ShowDialog()
$FolderBrowser.SelectedPath
$PlaylistName = Get-FileName "C:\Users\Trent\Music\Playlists"
$Directory = Read-Host 'Target Directory (Include drive and path)'
Write-Host "Searching "$PlaylistName" for media files and copying to "$Directory"`n"
Get-Content $PlaylistName | ? { $_ -and (Test-Path $_) } | Out-File Temp.txt
Get-Content Temp.txt | Copy-Item -Destination $Directory
write-host "Operation Completed."
