PowerShell Tips--Divide large files in a folder into several _powershell

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.