dropbox1349

Raggruppare le cartelle in accordo ad una parola chiave presente nel suo nome

Mar 26th, 2021 (edited)
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Video youtube:
  2. youtu.be/3SF20MpsJdY
  3. --------------------------
  4.  
  5. $SourcePath = 'C:\xxx\1'
  6. $TargetPath = 'C:\xxx\2'
  7.  
  8. $FolderList = Get-ChildItem -Path $SourcePath -Filter "*volume*" -Directory
  9.  
  10. foreach ($Folder in $FolderList) {
  11.     $Name1 = ($Folder.Name -split '-')[0].Trim()
  12.     $TargetFolder = Join-Path -Path $TargetPath -ChildPath $Name1
  13.     if (-not (Test-Path -Path $TargetFolder)) {
  14.         New-Item -Path $TargetFolder -ItemType Directory | Out-Null
  15.     }
  16.     Move-Item -Path $Folder.FullName -Destination $TargetFolder
  17. }
  18.  
  19.  
  20.  
  21. ***************************************
  22. VERSIONE ALTERNATIVA :: usare la versione 7 di Powershell !!
  23. ***************************************
  24. I see that you have selected an answer. Here is another way.
  25.  
  26. # Setup test data
  27. $Dirs = @(
  28.     'Absolute Moebius - Volume 2 - The Long Tomorrow'
  29.     ,'Absolute Moebius - Volume 3'
  30.     ,'Agenzia X - Volume 1 - La Recluta'
  31.     ,'Agenzia X - Volume 2 - Black Point'
  32.     ,'Agenzia X - Volume 3 - Soli'
  33.     ,'Akira - Volume 10'
  34.     ,'Akira - Volume 20'
  35.     ,'Akira - Volume 23'
  36.     ,'Alan Ford - Volume 11 - Il Numero Uno'
  37.     ,'Alan Ford - Volume 12 - La Triste Storia Di Un Giovane Ricco'
  38.     ,'Alan Ford - Volume 13 - Golf'
  39. )
  40. foreach ($Dir in $Dirs) {
  41.     if (-not (Test-Path -Path $Dir)) { New-Item -ItemType Directory -Path $Dir | Out-Null }
  42. }
  43.  
  44. # Code to move files starts here vvvvvvvvvvvvvvvvvvvv
  45. (Get-ChildItem -Directory -Filter '* - Volume*').Name |
  46.     ForEach-Object {
  47.         $NewDirName = $_.Split(' - ')[0]
  48.         if (-not (Test-Path -Path $NewDirName)) { New-Item -ItemType Directory -Path $NewDirName | Out-Null }
  49.         Move-Item -Path $_ -Destination $NewDirName
  50.     }
  51. # Code to move files ends here ^^^^^^^^^^^^^^^^^^^
Add Comment
Please, Sign In to add comment