Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2018
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. # Retrieve the list of files
  2. # $sDir = Source Directory
  3. $sDir = "U:\Test\"
  4. # Generate a list of all files in source directory
  5. $Files = (Get-ChildItem $sDir)
  6. # $tDir = Root Target Directory
  7. $tDir = "N:\Test\"
  8.  
  9. # Loop through our list of file names
  10. foreach($File in $Files)
  11. {
  12. # $wFile = working file name
  13. $wFile = $File.Name
  14.  
  15.  
  16. # End of IF tests where pulling based on file no prefix would be
  17.  
  18. # $nfold = The name of the sub-folder that the files will go into
  19. # Ideally wFile would be like, wFile(only take prefix string)
  20. $nFold = $wFile
  21.  
  22. # dFold = the destination folder in the format of \\drive\folder\SubFolder\
  23. $dFold = "$tDir$nFold"
  24.  
  25. # Test if the destination folder exists
  26. if(Test-Path $dFold -PathType Container)
  27. {
  28. # If the folder exists then we move the file
  29. Move-Item -Path $sDir$File -Destination $dFold
  30.  
  31. # Now we just write put what went where
  32. Write-Host $File "Was Moved to:" $dFold
  33. Write-Host
  34. }
  35. # If the folder does not exist then we leave it alone!
  36. else
  37. {
  38. # We write our selves a note that it was not moved
  39. Write-Host $File "Was not moved!"
  40. }
  41.  
  42. # End of the line folks
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement