PowerShell script useful for playing back in Cartrain CP7##BMW devices (currently CP700BMW, CP730BMW, CP740BMW) as these play back in the order in which directories and files have been created.
Posted by jpluimers on 2026/06/10
[Wayback/Archive] This is useful for playing back in Cartrain CP7##BMW devices (currently CP700BMW, CP730BMW, CP740BMW) as these play back in the order in which directories and files have been created. which is related to Elektronik-Idee – CP740BMW – USB wireless MP3 Player (with Bluetooth and Audio/Video in support) and fully PowerShell 2.0 compatible:
Script to recursively copy directories in alphabetical order from source-base-directory to destination-base-directory while adding an intermediate directory with a single uppercase letter in destination-base-directory for each set of directories under source-base-directory starting with that letter. This is useful for playing back in Cartrain CP7##BMW devices (currently CP700BMW, CP730BMW, CP740BMW) as these play back in the order in which directories and files have been created, as per: - https://www.cartain.de/downloads/cp740bmw/CP740BMW-OM.pdf Unterordner sind hervorragend geeignet um Musik besser zu organisieren. Dateinamen und Unterverzeichnis sind in der Reihenfolge gleichgestellt. Die Wiedergabe der Titel in sämtlichen Unterordnern erfolgt der Reihe nach wie sie auf den USB Stick kopiert wurde - https://www.cartain.de/downloads/cp740bmw/CP740BMW-OM-EN.pdf Sub folders are a good possibility to organize your music collection. The order of playback is the same order you copied the files onto the card. - https://www.cartain.de/downloads/cp730bmw/CP730BMW-OM.pdf - https://www.cartain.de/downloads/cp730bmw/CP730BMW-OM-EN.pdf
–jeroen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# | |
| Script to recursively copy directories in alphabetical order from source-base-directory to destination-base-directory | |
| while adding an intermediate directory with a single uppercase letter in destination-base-directory for | |
| each set of directories under source-base-directory starting with that letter. | |
| This is useful for playing back in Cartrain CP7##BMW devices (currently CP700BMW, CP730BMW, CP740BMW) | |
| as these play back in the order in which directories and files have been created, as per: | |
| – https://www.cartain.de/downloads/cp740bmw/CP740BMW-OM.pdf | |
| Unterordner sind hervorragend geeignet um Musik besser zu organisieren. Dateinamen und Unterverzeichnis sind in der Reihenfolge gleichgestellt. Die Wiedergabe der Titel in sämtlichen Unterordnern erfolgt der Reihe nach wie sie auf den USB Stick kopiert wurde | |
| – https://www.cartain.de/downloads/cp740bmw/CP740BMW-OM-EN.pdf | |
| Sub folders are a good possibility to organize your music collection. The order of playback is the same order you copied the files onto the card. | |
| – https://www.cartain.de/downloads/cp730bmw/CP730BMW-OM.pdf | |
| – https://www.cartain.de/downloads/cp730bmw/CP730BMW-OM-EN.pdf | |
| #> | |
| if ($Args.Count -lt 2) { | |
| # https://stackoverflow.com/questions/5466329/whats-the-best-way-to-determine-the-location-of-the-current-powershell-script | |
| # https://www.tutorialspoint.com/how-to-get-the-path-of-the-currently-executing-script-in-powershell | |
| $ScriptPath = $MyInvocation.MyCommand.Path | |
| Write-Output "$ScriptPath source-base-directory destination-base-directory" | |
| Write-Output "" | |
| Write-Output "Recursively copies in alphabetical order all directories/files" | |
| Write-Output "source-base-directory to destination-base-directory" | |
| Write-Output "adding an intermediate uppercase letter to destination-base-directory." | |
| } | |
| else { | |
| $SourceDirectory = $args[0] | |
| $DestinationDirectory = $args[1] | |
| Write-Output "Source: $SourceDirectory" | |
| Write-Output "Destination: $DestinationDirectory" | |
| # https://devblogs.microsoft.com/powershell-community/determine-if-a-folder-exists/ | |
| # http://adamringenberg.com/powershell2/test-path/ | |
| if (Test-Path -Path $SourceDirectory) { | |
| # https://stackoverflow.com/questions/8095638/how-do-i-negate-a-condition-in-powershell | |
| if (-Not (Test-Path -Path $DestinationDirectory)) { | |
| Write-Output "Destination path does not yet exist, creating: $DestinationDirectory" | |
| # https://www.tutorialspoint.com/powershell/powershell_files_create_folders.htm | |
| # https://stackoverflow.com/questions/46586382/hide-powershell-output | |
| $ null = New-Item -Path $DestinationDirectory -ItemType Directory | |
| } | |
| # https://stackoverflow.com/questions/3085295/how-do-i-get-only-directories-using-get-childitem | |
| # http://adamringenberg.com/powershell2/tag/unique/ | |
| $SourceSubDirectoryNames = Get-ChildItem $SourceDirectory | ?{ $_.PSIsContainer } | Sort-Object -Unique | |
| # https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/foreach-object?view=powershell-7.3 | |
| $SourceSubDirectoryNames | ForEach-Object { | |
| # use $_.FullName to get the full path | |
| $SourceSubDirectoryPath = $_.FullName | |
| $SourceSubDirectoryName = $_.Name | |
| $SourceSubDirectoryFirstUppercaseLetter = $SourceSubDirectoryName.SubString(0,1).ToUpper() | |
| Write-Output "$SourceSubDirectoryFirstUppercaseLetter->$SourceSubDirectoryName" | |
| # https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/join-path?view=powershell-7.3 | |
| $DestinationDirectoryWithLetter = Join-Path -Path $DestinationDirectory -ChildPath $SourceSubDirectoryFirstUppercaseLetter | |
| if (-Not (Test-Path -Path $DestinationDirectoryWithLetter)) { | |
| Write-Output "Destination path with letter does not yet exist, creating: $DestinationDirectoryWithLetter" | |
| $null = New-Item -Path $DestinationDirectoryWithLetter -ItemType Directory | |
| } | |
| $DestinationSubDirectoryPath = Join-Path -Path $DestinationDirectoryWithLetter -ChildPath $SourceSubDirectoryName | |
| Write-Output "Recursively copying from '$SourceSubDirectoryPath' to '$DestinationSubDirectoryPath'" | |
| # https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/copy-item?view=powershell-7.3 | |
| ## TODO: exclude hidden files | |
| Copy-Item -Path $SourceSubDirectoryPath -Destination $DestinationSubDirectoryPath -Recurse | |
| } | |
| Write-Output "Done." | |
| } else { | |
| Write-Output "Source path does not exist: $SourceDirectory" | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @for %%d in (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z) do mkdir %%d |






Leave a comment