I have found a PowerShell script which is capable of moving 'n' number of files from 'D:source' to 'E:Dest' directory. It will take the first 'n' number of files in the source folder and move them to the specified subfolder. It can create folders as long as they are needed.
Code:
$filesperfolder = 150
$sourcePath = "D:source"
$destPath = "E:Dest"
$i = 0;
$folderNum = 1;
Get-ChildItem "$sourcePath*.jpg" | % {
New-Item -Path ($destPath + "" + $folderNum) -Type Directory -Force
Move-Item $_ ($destPath + "" + $folderNum);
$i++;
if ($i -eq $filesperfolder){
$folderNum++;
$i = 0 ;
}
}
So far this script is working fine but, how do I set its working directory. I mean, if the script is on 'C: est' folder, then it should search that current folder for '*.jpg' files and create folders on that same directory.
See Question&Answers more detail:os