Friends have a folder, all are eml files, about 20G. He needs to divide the 20G files into 10 pieces per folder 2G. The following script was written:
#目标文件夹
$scrfile = "D:\test"
#起始目录名
$directory = 0
#1825361100
#76547428
# Determine when the number of files in the directory is greater than 0 o'clock while the loop is true while
(Dir-path $scrfile-filter *.eml). COUNT-GT 0)
{
#起始目录名为1
$directory + +
#建立目录
new-item-path "D:\ $directory"-itemtype directory-erroraction Stop
#累加大小变量
$length = 0< c15/> #dir配合where-object move files to the new directory, record size, and when size reaches the specified size, jumps out of the pipe.
Dir-path $scrfile-filter *.eml | where-object{
$objName = $_. Name
$_.moveto ("D:\ $directory \ $objName")
$length + + = $_.length
if ($length-gt 1825361100)
{ Continue}}}
Note that dir is best to use where-object here instead of foreach.
In this way, a friend of about 4W eml Mail folder, instantly in 2 seconds into 10 directories.