Advertisement
Guest User

GR-1-SampleOrganizer.ps1

a guest
Apr 25th, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Split files into separate directories based on specified "FilesPerFolder" default is 15 based on GR-1 file browser
  2.  
  3. param(
  4. [Parameter(Mandatory=$true,HelpMessage="This is the location of a directory that contains samples, it will be broken into numbered folders to reduce the number of samples in a single folder.")]
  5. [string]$Directory,
  6. [int]$FilesPerFolder = 15
  7. )
  8.  
  9. # Set Variables
  10. [int]$DirectoryCounter = 1
  11. [int]$FileCounter = 0
  12.  
  13. # Get List of Sample Files in Directory Specified
  14. $Include = "*.wav","*.ogg","*.flac","*.aiff","*.avr","*.XI"
  15. $DirectoryWC = $Directory + "\*"
  16. $SampleFiles = Get-ChildItem -Path $DirectoryWC -Include $Include
  17.  
  18. # Create the first subfolder
  19. $NewDirectory = ("{0:d2}" -f $DirectoryCounter).ToString()
  20. New-Item -ItemType Directory -Path $Directory\$NewDirectory -Force
  21.  
  22. foreach ($File in $SampleFiles)
  23. {  
  24.     $FileCounter ++
  25.  
  26.     # Move Files to new Dir
  27.     $Destination = $NewDirectory + "\" + $file.Name
  28.     Move-Item -Path $File.FullName -Destination $Destination -Verbose
  29.    
  30.     If ($FileCounter -eq $FilesPerFolder)
  31.     {
  32.         $FileCounter = 0
  33.         $DirectoryCounter ++
  34.  
  35.         # Create subsequent subfolder(s)
  36.         $NewDirectory = ("{0:d2}" -f $DirectoryCounter).ToString()
  37.         New-Item -ItemType Directory -Path $Directory\$NewDirectory -Force
  38.     }  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement