Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Retrieve the list of files
- # $sDir = Source Directory
- $sDir = "U:\Test\"
- # Generate a list of all files in source directory
- $Files = (Get-ChildItem $sDir)
- # $tDir = Root Target Directory
- $tDir = "N:\Test\"
- # Loop through our list of file names
- foreach($File in $Files)
- {
- # $wFile = working file name
- $wFile = $File.Name
- # End of IF tests where pulling based on file no prefix would be
- # $nfold = The name of the sub-folder that the files will go into
- # Ideally wFile would be like, wFile(only take prefix string)
- $nFold = $wFile
- # dFold = the destination folder in the format of \\drive\folder\SubFolder\
- $dFold = "$tDir$nFold"
- # Test if the destination folder exists
- if(Test-Path $dFold -PathType Container)
- {
- # If the folder exists then we move the file
- Move-Item -Path $sDir$File -Destination $dFold
- # Now we just write put what went where
- Write-Host $File "Was Moved to:" $dFold
- Write-Host
- }
- # If the folder does not exist then we leave it alone!
- else
- {
- # We write our selves a note that it was not moved
- Write-Host $File "Was not moved!"
- }
- # End of the line folks
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement