PDA

View Full Version : RICHIESTA DI UN COMANDO PER POWERSHELL


pistorius08
29-10-2024, 10:08
Ciao a tutti ho un quesito: siccome ho circa 4/5cento di GB di musica vorrei sistemarla, avrei bisogno di un COMANDO per powershell che scansioni la cartella dove tengo la musica e mi permetta di: prendere tutte le cartelle che contengono i file .mp3 spostandole in un’ altra cartella eliminando i file .mp3 al suo interno ma mantenendo nome e “albero” delle sopracartelle, cioè : se ad esempio la cartella che contiene i file .mp3 si chiama CD2 contenuta all’interno di MUSICA>nome artista>titolo album>CD2, il risultato finale sarà una cartella chiamata MUSICA1 con all’interno tutte le sotto cartelle vuote. E’ possibile? Grazie

pps
29-10-2024, 10:22
Ciao a tutti ho un quesito: siccome ho circa 4/5cento di GB di musica vorrei sistemarla, avrei bisogno di un COMANDO per powershell che scansioni la cartella dove tengo la musica e mi permetta di: prendere tutte le cartelle che contengono i file .mp3 spostandole in un’ altra cartella eliminando i file .mp3 al suo interno ma mantenendo nome e “albero” delle sopracartelle, cioè : se ad esempio la cartella che contiene i file .mp3 si chiama CD2 contenuta all’interno di MUSICA>nome artista>titolo album>CD2, il risultato finale sarà una cartella chiamata MUSICA1 con all’interno tutte le sotto cartelle vuote. E’ possibile? Grazie
Prova con questo, copia e incolla il codice e salva come .Ps1.
NOTA BENE
ho scritto il codice "al volo" e non l'ho testato, quindi prima di metterlo "in produzione" creati due cartelle di "origine" e "destinazione" e fai una prova.
(non voglio averti sulla coscenza):)
P.S. modifica "al bisogno" i percorsi di source e destination delle prime due righe.
Aggiornami se funziona / va bene cosi / dobbiamo fare delle modifiche...
$sourcePath = "C:\percorso\alla\tuacartella\musica"
$destinationPath = "C:\percorso\alla\nuovacartella\MUSICA1"

# Ottieni tutte le cartelle che contengono file .mp3
$foldersWithMp3 = Get-ChildItem -Path $sourcePath -Recurse -Directory | Where-Object {
Get-ChildItem -Path $_.FullName -Filter *.mp3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
}

# Sposta le cartelle nella nuova posizione e elimina i file .mp3
foreach ($folder in $foldersWithMp3) {
$newFolderPath = Join-Path -Path $destinationPath -ChildPath $folder.FullName.Substring($sourcePath.Length)
New-Item -ItemType Directory -Path $newFolderPath -Force
Remove-Item -Path (Join-Path -Path $folder.FullName -ChildPath "*.mp3") -Force
}

SysLack
29-10-2024, 11:49
Dovrebbe funzionare anche qualcosa di più semplice come:
$sourcePath = "C:\percorso\alla\tuacartella\musica"
$destinationPath = "C:\percorso\alla\nuovacartella\MUSICA1"
Copy-Item $sourcePath $destinationPath -Recurse -Exclude "*.mp3"
Nella cartella di destinazione verranno esclusi solo i file MP3; se ci sono immagini, copertine o altro, saranno copiate (per non copiarle basta aggiungere la loro estensione a -Exclude).
Nei test rapidi che ho fatto, il codice funziona come previsto, ma resta valido il consiglio di fare prima qualche prova con qualche tua "cartella cavia".

pistorius08
29-10-2024, 15:17
Risposta al primo codice @pps

Microsoft Windows [Versione 10.0.26100.2161]
(c) Microsoft Corporation. Tutti i diritti riservati.

C:\Users\umber>$sourcePath = "C:\Users\umber\Music\1-da sistemare"
"$sourcePath" non è riconosciuto come comando interno o esterno,
un programma eseguibile o un file batch.

C:\Users\umber>$destinationPath = "C:\Users\umber\Music\MUSICA1"
"$destinationPath" non è riconosciuto come comando interno o esterno,
un programma eseguibile o un file batch.

C:\Users\umber># Ottieni tutte le cartelle che contengono file .mp3
"#" non è riconosciuto come comando interno o esterno,
un programma eseguibile o un file batch.

C:\Users\umber>$foldersWithMp3 = Get-ChildItem -Path $sourcePath -Recurse -Directory | Where-Object {Get-ChildItem -Path $_.FullName -Filter *.mp3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0}
"$foldersWithMp3" non è riconosciuto come comando interno o esterno,
un programma eseguibile o un file batch.

C:\Users\umber># Sposta le cartelle nella nuova posizione e elimina i file .mp3
"#" non è riconosciuto come comando interno o esterno,
un programma eseguibile o un file batch.

C:\Users\umber>foreach ($folder in $foldersWithMp3) {
"foreach" non è riconosciuto come comando interno o esterno,
un programma eseguibile o un file batch.

C:\Users\umber> $newFolderPath = Join-Path -Path $destinationPath -ChildPath $folder.FullName.Substring($sourcePath.Length)
"$newFolderPath" non è riconosciuto come comando interno o esterno,
un programma eseguibile o un file batch.

C:\Users\umber> New-Item -ItemType Directory -Path $newFolderPath -Force
"New-Item" non è riconosciuto come comando interno o esterno,
un programma eseguibile o un file batch.

C:\Users\umber> Remove-Item -Path (Join-Path -Path $folder.FullName -ChildPath "*.mp3") -Force}
"Remove-Item" non è riconosciuto come comando interno o esterno,
un programma eseguibile o un file batch.


risposta al secondo codice @SysLack

Microsoft Windows [Versione 10.0.26100.2161]
(c) Microsoft Corporation. Tutti i diritti riservati.

C:\Users\umber>$sourcePath = "C:\Users\umber\Music\1-da sistemare"
"$sourcePath" non è riconosciuto come comando interno o esterno,
un programma eseguibile o un file batch.

C:\Users\umber>$destinationPath = "C:\Users\umber\Music\MUSICA1"
"$destinationPath" non è riconosciuto come comando interno o esterno,
un programma eseguibile o un file batch.

C:\Users\umber>Copy-Item $sourcePath $destinationPath -Recurse -Exclude "*.mp3"
"Copy-Item" non è riconosciuto come comando interno o esterno,
un programma eseguibile o un file batch.

Grazie per il vostro interessamento. Umberto

Nicodemo Timoteo Taddeo
29-10-2024, 15:22
Stai operando dal prompt dei comandi non da Power Shell, o sbaglio? :confused:

SysLack
29-10-2024, 16:12
Se vuoi usarlo come codice direttamente dal terminale, quindi senza fare copia-codice/incolla-su-file-di-testo/salva-come-PS1 (come suggerito da pps), allora devi avviare PowerShell (tasto destro su menu start / Windows PowerShell), incollare questo codice e poi modificare i percorsi prima di premere invio:
$sourcePath = "C:\percorso\alla\tuacartella\musica" ; $destinationPath = "C:\percorso\alla\nuovacartella\MUSICA1" ; Copy-Item $sourcePath $destinationPath -Recurse -Exclude "*.mp3"
https://i.postimg.cc/tg7C4zmM/MP3less.gif
Con Windows 11 la procedura è la medesima.

pistorius08
29-10-2024, 16:14
Ops hai ragione pensavo fosse la stessa cosa :muro: :muro: :muro: :muro:

pistorius08
29-10-2024, 16:21
Dovrebbe funzionare anche qualcosa di più semplice come:
$sourcePath = "C:\percorso\alla\tuacartella\musica"
$destinationPath = "C:\percorso\alla\nuovacartella\MUSICA1"
Copy-Item $sourcePath $destinationPath -Recurse -Exclude "*.mp3"
Nella cartella di destinazione verranno esclusi solo i file MP3; se ci sono immagini, copertine o altro, saranno copiate (per non copiarle basta aggiungere la loro estensione a -Exclude).
Nei test rapidi che ho fatto, il codice funziona come previsto, ma resta valido il consiglio di fare prima qualche prova con qualche tua "cartella cavia".

Ho provato da powershell ma non ha funzionato, in pratica ha copiato tutte le cartelle della "sorgente" in quella di destinazione, compresi tutti i file FLAC , l'operazione non è finita per mancanza di spazio, non so se gli mp3 sono stati eliminati.....adesso controllo

pistorius08
29-10-2024, 16:34
@pps
$sourcePath = "C:\percorso\alla\tuacartella\musica"
$destinationPath = "C:\percorso\alla\nuovacartella\MUSICA1"

# Ottieni tutte le cartelle che contengono file .mp3
$foldersWithMp3 = Get-ChildItem -Path $sourcePath -Recurse -Directory | Where-Object {
Get-ChildItem -Path $_.FullName -Filter *.mp3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
}

# Sposta le cartelle nella nuova posizione e elimina i file .mp3
foreach ($folder in $foldersWithMp3) {
$newFolderPath = Join-Path -Path $destinationPath -ChildPath $folder.FullName.Substring($sourcePath.Length)
New-Item -ItemType Directory -Path $newFolderPath -Force
Remove-Item -Path (Join-Path -Path $folder.FullName -ChildPath "*.mp3") -Force
}
[/CODE]

PowerShell 7.4.6

Do you want to run software from this untrusted publisher?
File C:\users\umber\0-portable\powershell-7.4.6-win-x64\Modules\PSReadLine\PSReadLine.format.ps1xml is published by
CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US and is not trusted on your system.
Only run scripts from trusted publishers.
[V] Never run [D] Do not run [R] Run once [A] Always run [?] Help (default is "D"): d
Cannot load PSReadline module. Console is running without PSReadline.
PS C:\Users\umber\0-PORTABLE\PowerShell-7.4.6-win-x64> $sourcePath = "C:\Users\umber\Music\1-da sistemare"
PS C:\Users\umber\0-PORTABLE\PowerShell-7.4.6-win-x64> $destinationPath = "C:\Users\umber\Music\MUSICA1"
PS C:\Users\umber\0-PORTABLE\PowerShell-7.4.6-win-x64> # Ottieni tutte le cartelle che contengono file .mp3
PS C:\Users\umber\0-PORTABLE\PowerShell-7.4.6-win-x64> $foldersWithMp3 = Get-ChildItem -Path $sourcePath -Recurse -Directory | Where-Object {Get-ChildItem -Path $_.FullName -Filter *.mp3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0}
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
Select-Object: A parameter cannot be found that matches parameter name 'eq'.
PS C:\Users\umber\0-PORTABLE\PowerShell-7.4.6-win-x64> # Sposta le cartelle nella nuova posizione e elimina i file .mp3
PS C:\Users\umber\0-PORTABLE\PowerShell-7.4.6-win-x64> foreach ($folder in $foldersWithMp3) {
>> $newFolderPath = Join-Path -Path $destinationPath -ChildPath $folder.FullName.Substring($sourcePath.Length)
>> New-Item -ItemType Directory -Path $newFolderPath -Force
>> Remove-Item -Path (Join-Path -Path $folder.FullName -ChildPath "*.mp3") -Force}

SysLack
29-10-2024, 16:51
Ho provato da powershell ma non ha funzionato, in pratica ha copiato tutte le cartelle della "sorgente" in quella di destinazione, compresi tutti i file FLAC , l'operazione non è finita per mancanza di spazio, non so se gli mp3 sono stati eliminati.....adesso controllo
Lo scopo non era forse copiare le cartelle mantenendo l'albero delle sottocartelle, eliminando tutti gli MP3? Se vuoi eliminare anche i .flac, devi modificare la fine del codice con:
-Exclude "*.mp3","*.flac"
Al bisogno, puoi aggiungere anche altre estensioni, oppure essere più drastico ed eliminare ogni file (se non ti ricordi tutti i tipi di file presenti), con
-Exclude "*.*"

pistorius08
29-10-2024, 17:34
@SysLack
il tuo comando funziona quasi alla perfezione, ho provato con un album che sapevo contenesse mp3, il risultato è la nuova cartella senza gli mp3 con all'interno le 3 cartelle originali, CD1 CD2 contenenti le immagini di artist front back disc, la terza cartella cover con all'interno le vari immagini e il pdf dell'album fino qua tutto bene, ma non ha eliminato/spostato la cartella sorgente che è rimasta immutata, in conclusione: il tuo comando copia tutte le cartelle della sorgente contenenti mp3 e FLAC svuotando gli mp3 nella destinazione , mentre a me occorrerebbe che le cartelle dei FLAC non vengano copiate mentre quelle degli mp3 vengano svuotate dagli mp3 e tagliate/incollate nella cartella di destinazione, penso proprio che se la cosa si possa fare di sicuro tu troverai la soluzione
GRAZIE GRAZIE GRAZIE
P.S. Sono migliaia di cartelle non mi ricordo quali siano quelle contenenti gli mp3......e non voglio copiare nulla perchè non avrei abbastanza spazio visto che sono 4/500 GB di "roba" se poi le copia tutte il nr raddoppia....e le cartelle che contengono gli mp3 restano immutate al loro posto, e io vorrei che queto non succedesse. Scusami tanto se ti stò facendo tribulare. Umberto

pistorius08
29-10-2024, 20:51
Prova con questo, copia e incolla il codice e salva come .Ps1.
NOTA BENE
ho scritto il codice "al volo" e non l'ho testato, quindi prima di metterlo "in produzione" creati due cartelle di "origine" e "destinazione" e fai una prova.
(non voglio averti sulla coscenza):)
P.S. modifica "al bisogno" i percorsi di source e destination delle prime due righe.
Aggiornami se funziona / va bene cosi / dobbiamo fare delle modifiche...
$sourcePath = "C:\percorso\alla\tuacartella\musica"
$destinationPath = "C:\percorso\alla\nuovacartella\MUSICA1"

# Ottieni tutte le cartelle che contengono file .mp3
$foldersWithMp3 = Get-ChildItem -Path $sourcePath -Recurse -Directory | Where-Object {
Get-ChildItem -Path $_.FullName -Filter *.mp3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
}

# Sposta le cartelle nella nuova posizione e elimina i file .mp3
foreach ($folder in $foldersWithMp3) {
$newFolderPath = Join-Path -Path $destinationPath -ChildPath $folder.FullName.Substring($sourcePath.Length)
New-Item -ItemType Directory -Path $newFolderPath -Force
Remove-Item -Path (Join-Path -Path $folder.FullName -ChildPath "*.mp3") -Force
}


Questo il risultato ma sembra non aver fatto nulla

PowerShell 7.3.8


PS C:\Users\umber\Music\prova mp3.1> $sourcePath = "C:\Users\umber\Music\prova mp3.1\MUSICA"
PS C:\Users\umber\Music\prova mp3.1> $destinationPath "C:\Users\umber\Music\prova mp3.1\MUSICA1"
ParserError:
Line |
1 | $destinationPath "C:\Users\umber\Music\prova mp3.1\MUSICA1"
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Unexpected token '"C:\Users\umber\Music\prova mp3.1\MUSICA1"' in expression or statement.
PS C:\Users\umber\Music\prova mp3.1>
PS C:\Users\umber\Music\prova mp3.1> # Ottieni tutte le cartelle che contengono file .mp3
PS C:\Users\umber\Music\prova mp3.1> $foldersWithMp3 = Get-ChildItem -Path $sourcePath -Recurse -Directory | Where-Object {
>> Get-ChildItem -Path $_.FullName -Filter *.mp3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
>> }
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
Select-Object:
Line |
2 | … p3 -File | Measure-Object | Select-Object -ExpandProperty Count -eq 0
| ~~~
| A parameter cannot be found that matches parameter name 'eq'.
PS C:\Users\umber\Music\prova mp3.1>
PS C:\Users\umber\Music\prova mp3.1> # Sposta le cartelle nella nuova posizione e elimina i file .mp3
PS C:\Users\umber\Music\prova mp3.1> foreach ($folder in $foldersWithMp3) {
>> $newFolderPath = Join-Path -Path $destinationPath -ChildPath $folder.FullName.Substring($sourcePath.Length)
>> New-Item -ItemType Directory -Path $newFolderPath -Force
>> Remove-Item -Path (Join-Path -Path $folder.FullName -ChildPath "*.mp3") -Force
>> }
PS C:\Users\umber\Music\prova mp3.1>

pistorius08
29-10-2024, 22:35
Dovrebbe funzionare anche qualcosa di più semplice come:
$sourcePath = "C:\percorso\alla\tuacartella\musica"
$destinationPath = "C:\percorso\alla\nuovacartella\MUSICA1"
Copy-Item $sourcePath $destinationPath -Recurse -Exclude "*.mp3"
Nella cartella di destinazione verranno esclusi solo i file MP3; se ci sono immagini, copertine o altro, saranno copiate (per non copiarle basta aggiungere la loro estensione a -Exclude).
Nei test rapidi che ho fatto, il codice funziona come previsto, ma resta valido il consiglio di fare prima qualche prova con qualche tua "cartella cavia".

PowerShell 7.3.8

PS C:\Users\umber\Music\prova mp3.1> $sourcePath = "C:\Users\umber\Music\prova mp3.1\MUSICA"
PS C:\Users\umber\Music\prova mp3.1> $destinationPath = "C:\Users\umber\Music\prova mp3.1\MUSICA1"
PS C:\Users\umber\Music\prova mp3.1> Copy-Item $sourcePath $destinationPath -Recurse -Exclude "*.mp3"

Ho riprovato con una cartella piu corposa Per funzionare funziona ma copia anche le cartelle con i FLAC, ed avendo la cartella MUSICA di 568 GB non ho abbastanza spazio per svolgere l'operazione, l'ideale sarebbe avere come risultato finale solo le cartelle relative agli mp3 vuote e non ma penso che non si possa fare (spero di sbagliarmi). Ho pensato pure di prendere a blocchi le cartelle spostarle in un'altra cartella fare le operazioni ma sarei a punto e accapo perchè dovrei "spulciarle" una ad una per capire quali sono le cartelle con gli mp3, prendere quelle con i FLAC e rispostarle nella cartella originale (MUSICA) e poi perderei le personalizzazioni di tutte le cartelle che ho tipo queste

https://i.postimg.cc/8fBWRp2K/Screenshot-2024-10-29-223414.png (https://postimg.cc/8fBWRp2K)

Mi sembra un po come il cane che si morde la coda, sto pensando di abbandonare la mia malsana idea :cry: :cry: anche se la speranza è l'ultima a morire. Grazie Mille per il tempo dedicatomi

pps
30-10-2024, 09:44
PowerShell 7.3.8

PS C:\Users\umber\Music\prova mp3.1> $sourcePath = "C:\Users\umber\Music\prova mp3.1\MUSICA"
PS C:\Users\umber\Music\prova mp3.1> $destinationPath = "C:\Users\umber\Music\prova mp3.1\MUSICA1"
PS C:\Users\umber\Music\prova mp3.1> Copy-Item $sourcePath $destinationPath -Recurse -Exclude "*.mp3"

Ho riprovato con una cartella piu corposa Per funzionare funziona ma copia anche le cartelle con i FLAC, ed avendo la cartella MUSICA di 568 GB non ho abbastanza spazio per svolgere l'operazione, l'ideale sarebbe avere come risultato finale solo le cartelle relative agli mp3 vuote e non ma penso che non si possa fare (spero di sbagliarmi). Ho pensato pure di prendere a blocchi le cartelle spostarle in un'altra cartella fare le operazioni ma sarei a punto e accapo perchè dovrei "spulciarle" una ad una per capire quali sono le cartelle con gli mp3, prendere quelle con i FLAC e rispostarle nella cartella originale (MUSICA) e poi perderei le personalizzazioni di tutte le cartelle che ho tipo queste

https://i.postimg.cc/8fBWRp2K/Screenshot-2024-10-29-223414.png (https://postimg.cc/8fBWRp2K)

Mi sembra un po come il cane che si morde la coda, sto pensando di abbandonare la mia malsana idea :cry: :cry: anche se la speranza è l'ultima a morire. Grazie Mille per il tempo dedicatomi

...mi sà che devo fare un pò di DEBUG...

SysLack
30-10-2024, 11:47
a me occorrerebbe che le cartelle dei FLAC non vengano copiate mentre quelle degli mp3 vengano svuotate dagli mp3 e tagliate/incollate nella cartella di destinazione
Questo codice va copiato su un file di testo (Blocco Note), modificato con i percorsi giusti ($Sorgente e $Destinazione), salvato con estensione .PS1 e lanciato con PowerShell (tasto destro sul file e "Esegui con PowerShell"). Non fare copia e incolla direttamente sul terminale. Se il file PS1 non viene eseguito, apri PowerShell ed esegui il comando
powershell.exe -ep bypass C:\percorso file.PS1
Dovrebbe fare esattamente ciò che intendi, ma è da considerare che i file MP3 saranno cancellati e quindi non li avrai più né sulla cartella sorgente né in quella di destinazione (è quello che volevi, giusto?).
Fai dei test con una copia di alcune cartelle che vuoi spostare, così se qualcosa va storto, non perdi nulla. Considera inoltre che lo script cancellerà tutte le cartelle vuote che trova nella cartella sorgente.
Chiaramente valuta bene se è il caso di lanciare uno script che sposta e cancella file che non potrai più recuperare; ho fatto delle prove e sembra funzionare come desideri, ma onestamente non lo userei su file importanti di cui non ho il backup o che non posso recuperare in altro modo.

# Funzione per gestire percorso sottocartelle nella destinazione
function SubPath {
param (
[string]$BasePath,
[string]$FullPath
)
$BasePath = (Resolve-Path $BasePath).Path
$FullPath = (Resolve-Path $FullPath).Path
if (-not $BasePath.EndsWith('\')) {
$BasePath += '\'
}
if ($FullPath.StartsWith($BasePath)) {
return $FullPath.Substring($BasePath.Length)
} else {
return $FullPath
}
}


# Percorso cartelle DA MODIFICARE
$Sorgente = "C:\sorgente..."
$Destinazione = "C:\destinazione..."

# Estensione da rimuovere
$Estensione = "*.mp3"

# Individuazione sottocartelle
$SubFolders = Get-ChildItem -Path $Sorgente -Directory -Recurse

# Spostamento cartelle e rimozione MP3
foreach ($Folder in $SubFolders) {
# Individuazione cartelle da processare
if (Get-ChildItem -Path $Folder.FullName -Filter $Estensione -File -Recurse) {
# Creazione nuove cartelle nella destinazione
$DiffName = SubPath -BasePath $Sorgente -FullPath $Folder.FullName
New-Item -ItemType Directory "$(Join-Path -Path $Destinazione -ChildPath $DiffName)"
# Spostamento cartelle contenenti MP3
$NewPath = "$(Join-Path -Path $Destinazione -ChildPath $DiffName)"
Move-Item -Path "$($Folder.FullName)\*.*" -Destination $NewPath
# Rimozione MP3
Get-ChildItem -Path $NewPath -Filter $Estensione -File | Remove-Item -Force
}
}

# Cancellazione cartelle vuote nella sorgente
foreach ($DirEmpty in (Get-ChildItem $Sorgente -Recurse -Exclude *.*)) {
if ((Get-ChildItem $DirEmpty) -eq $null) {
Remove-Item $DirEmpty -Force
}
}

pistorius08
30-10-2024, 14:51
Questo codice va copiato su un file di testo (Blocco Note), modificato con i percorsi giusti ($Sorgente e $Destinazione), salvato con estensione .PS1 e lanciato con PowerShell (tasto destro sul file e "Esegui con PowerShell"). Non fare copia e incolla direttamente sul terminale. Se il file PS1 non viene eseguito, apri PowerShell ed esegui il comando
powershell.exe -ep bypass C:\percorso file.PS1
Dovrebbe fare esattamente ciò che intendi, ma è da considerare che i file MP3 saranno cancellati e quindi non li avrai più né sulla cartella sorgente né in quella di destinazione (è quello che volevi, giusto?).
Fai dei test con una copia di alcune cartelle che vuoi spostare, così se qualcosa va storto, non perdi nulla. Considera inoltre che lo script cancellerà tutte le cartelle vuote che trova nella cartella sorgente.
Chiaramente valuta bene se è il caso di lanciare uno script che sposta e cancella file che non potrai più recuperare; ho fatto delle prove e sembra funzionare come desideri, ma onestamente non lo userei su file importanti di cui non ho il backup o che non posso recuperare in altro modo.

RISULTATO SCRIPT

ORIGINE (SITUAZIONE ORIGINE) DESTINAZIONE

cartella solo mp3 (cartella eliminata) cartella vuota
cartella mp3+immagini (cartella eliminata) cartella solo immagini
cartella mp3+immagini+cartella (cartella con cartella) cartella solo immagini
cartella mp3+FLAC+immagini+cartella (cartella con cartella) cartella FLAC+immagini
cartella cartelle (mp3+immagini)-- (cartella vuota) cartella cartelle (immagini)--
cartella cartelle (mp3)-- (cartella vuota) cartella cartelle (vuote)
cartella solo FLAC (cartella solo FLAC) inesistente

Se non è abbastanza chiaro forse qui lo è
https://drive.google.com/file/d/1DM5S-Ap7fgtzJyQq-B9nuaszdZD2_5OE/view?usp=drive_link

sembra funzionare anche se c'è da lavorare (io) ancora un pò: per spulciare il tutto eliminare. spostare le cartelle ma è già un'OTTIMO risultato :yeah: :yeah: :yeah:
Un' IMMENNSO GRAZIE Syslcak sei un :angel: :cincin: :cincin:

SysLack
30-10-2024, 16:50
Bene, mi sembra di capire che lo script funzioni adeguatamente (il link google non è pubblico, non si apre senza account, ma mi fido del tuo verdetto). Se ci sono altre esigenze, si può provare anche a perfezionare il codice o aggiungere altre funzioni (se non sono faccende troppo complesse per me).

SysLack
30-10-2024, 18:44
cartella mp3+FLAC+immagini+cartella (cartella con cartella) cartella FLAC+immagini

Se interpreto bene, c'è nella sorgente almeno una cartella che contiene sia MP3 che FLAC, per cui quando tale cartella viene spostata vengono inviati anche i FLAC nella cartella di destinazione, che non è ciò che vorresti (giusto?). Per evitare che i FLAC vengano spostati nella cartella di destinazione, puoi aggiungere una riga di codice, così da ottenere:
...
# Spostamento cartelle contenenti MP3
$NewPath = "$(Join-Path -Path $Destinazione -ChildPath $DiffName)"
Move-Item -Path "$($Folder.FullName)\*.*" -Exclude "*.flac" -Destination $NewPath -ErrorAction Ignore # Preservazione file FLAC
# Rimozione MP3
Get-ChildItem -Path $NewPath -Filter $Estensione -File | Remove-Item -Force
...

Se poi desideri eliminare tutte le eventuali cartelle vuote anche nella cartella di destinazione, allora basta aggiungere questo alla fine dello script:
# Cancellazione cartelle vuote nella destinazione
foreach ($DirEmpty2 in (Get-ChildItem $Destinazione -Recurse -Exclude *.*)) {
if ((Get-ChildItem $DirEmpty2) -eq $null) {
Remove-Item $DirEmpty2 -Force
}
}

Sono delle aggiunte, quindi per tornare indietro al funzionamento precedente basta cancellarle.

pistorius08
30-10-2024, 20:24
https://i.postimg.cc/crJxFyDm/Screenshot-2024-10-30-193033.png (https://postimg.cc/crJxFyDm)

Quello dei FLAC + mp3 è l'unica cartella che avevo... era il brano "IL MARINAIO" (già recuperato in FLAC). ascoltalo https://www.youtube.com/watch?v=W_96mcW9qtI ma non scandalizzarti LOL. della Vanoni inserito da me nella cartella (album) "ORNELLA &...." esatto era L'UNICO. NON voglio eliminare le cartella vuote in destinazione perchè è la lista degli album che devo recuperare in FLAC. Per me va bene cosi perchè posso dargli in "pasto", alllo SCRIPT tutta la Cartella MUSICA senza avere problemi di "spazio", perchè l'mp3 ha un peso irrisorio: calcola che un brano in mp3 di media è 3 MB mentre in FLAC potrebbe arrivare senza problemi a una 40ina di MB e di album in mp3 ne ho relativamete pochi
SysLack SEI UN MITO :winner: :cincin: :cincin: GRAZIE GRAZIE GRAZIE Umberto

SysLack
30-10-2024, 21:47
Grazie a te per il riscontro; l'importante è aver raggiunto l'obiettivo (e aver ripassato un po' di PowerShell); chissà che un domani lo script non serva anche ad altri.

pistorius08
30-10-2024, 22:31
Io sono ormai un vecchietto e non tanto colto sui PC. Provo quello che mi suggeriscono e dò le mie impressioni su ciò che va e non va, come ho fatto con questa richiesta, i forum servono a questo sia nel presente che nel futuro anche se secondo me andrebbe perfezionato il "CERCA", ho provato adesso a "cercare" qualcosa per rainmeter che mi ero imbattuto diversi anni fa ma non ho trovato nulla (14 per l'esattezza controllato ora nel "ALCUNI MIEI DESKTOP" che ho in firma) un po la mancanza di tempo e il pc che mi aveva lasciato a "piedi" l'abbandonai adesso vorrei "riprenderlo in mano" mi piace personalizzare il desktop adesso ho questo si lo so sono di parte :Prrr: :Prrr:

https://i.postimg.cc/BvYy4kqJ/Screenshot-2024-10-30-222801.png (https://postimg.cc/Z9NjLfBQ)

Io direi che posso ritenermi soddisfatto per il risultato ottenuto GRAZIE MILLE ANCORA SysLack