SHARE
TWEET

Untitled

a guest Mar 26th, 2020 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $sorted_dir = "sorted_books"
  2. $without_book_id_dir = "$sorted_dir/books"
  3.  
  4. New-Item -Path . -Name $sorted_dir -ItemType "directory"
  5. New-Item -Path $without_book_id_dir -ItemType "directory"
  6.  
  7. Get-ChildItem . | ForEach-Object {
  8.     if (Test-Path -Path $_.Name -PathType Container) {
  9.         return
  10.     }
  11.  
  12.     $match = $_.Name -match 'book-(.+)\)'
  13.     $source = $_.Name
  14.  
  15.     # prettify
  16.     $extension = (Get-Item $_.Name).Extension
  17.     $full_name = $_.Name -Split "_"
  18.     $ugly_name = $full_name[0]
  19.     $pretty_name = ($ugly_name -Split "-" | ForEach-Object { $_.Substring(0, 1).ToUpper() + $_.Substring(1) }) -Join ' '
  20.  
  21.     $target = ''
  22.     if ($match) {
  23.         # with book id
  24.         $book_id = $Matches.1
  25.         $target = "$sorted_dir/$book_id/$pretty_name" + $extension
  26.  
  27.         if (!(Test-Path -Path "$sorted_dir/$book_id")) {
  28.             New-Item -Path "$sorted_dir/$book_id" -ItemType "directory"
  29.         }
  30.     } else {
  31.         # no book id
  32.         $target = "$without_book_id_dir/$pretty_name" + $extension
  33.     }
  34.  
  35.     "Copying: `n`t source:$source to `n`t target:$target"
  36.     Copy-Item $source -Destination $target
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top