thorpedosg

sDLiY3Sp

Aug 6th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. Batch copy files to new directories that match the file name
  2. 1a.jpg
  3. 1b.jpg
  4. 1c.jpg
  5.  
  6. 2a.jpg
  7. 2a.jpg
  8. 2c.jpg
  9.  
  10. @echo off
  11. setlocal EnableDelayedExpansion
  12. for %%f in (*.jpg) do (
  13. set dir=%%~Nf
  14. set dir=!dir:~0,-1!
  15. if not exist !dir! md !dir!
  16. copy %%f !dir!
  17. )
  18.  
  19. Get-ChildItem *.jpg | ForEach-Object {
  20. $destination = $_.FullName -replace '[a-f].jpg'
  21. if (-not (Test-Path -Path $destination -PathType Container)) {
  22. $null = New-Item -Path $destination -ItemType directory
  23. }
  24. Copy-Item -Path $_.FullName -Destination $destination
  25. }
  26.  
  27. Get-ChildItem -Filter *.jpg | Group-Object {$_.Name[0]} | Foreach-Object { $_.Group | Copy-Item -Destination "C:test$($_.Name)" }
  28.  
  29. Get-ChildItem *.jpg | Copy-Item -Destination { "C:test$($_.Name[0])" }
  30.  
  31. dir -filter *.jpg | % { Copy-Item -PATH $_ -DESTINATION .$($_.BaseName.ToCharArray()[0]) }
Add Comment
Please, Sign In to add comment