PowerShell Management Series (21) file merging in different folders of PowerShell operation

Source: Internet
Author: User

-----provide ad\exchange\lync\sharepoint\crm\sc\o365 and other Microsoft product implementation and outsourcing, qq:185426445. Phone 18666943750

Requirements: The server used several years down, found that our disk has a number of similar folders, we would like to merge this folder into a specified folder, and delete other unused folders.

Step 1, we open our server, D disk under the 5 years of Information Summary folder, some of the files are the same, some are different. such as:

650) this.width=650; "Width=" 864 "height=" 608 "title=" qq picture 20150212110724.png "style=" width:720px;height:472px; "alt= "Wkiol1tchpgc9le1aapnkxz4da4630.jpg" src= "Http://s3.51cto.com/wyfs02/M00/59/AE/wKioL1TcHpGC9le1AAPNKXz4da4630.jpg"/>

Step 2, search out the files of these 5 folders, and the previous year's folders and the latest "15 Information summary" to compare, such as the file name is not the same copy it to the "15 Information summary."

#不要遍历查找, subfolders copy directly $total 14=get-childitem "D:\ 14 Summary of information materials   | foreach {$_.name}  #不要遍历查找, subfolders copy directly $total 15=get-childitem "D:\ 15 Summary of information materials   | foreach {$_.name}  #不要遍历查找, subfolders copy directly

Get-childitem-recurse-path "d:\15 Annual Information Summary"-include "Copy file log. txt" | Clear-content
foreach ($a in $total 11)
{
if ($a 11-notin $total) #假如11年的文件夹里面的文件在15年文件夹里面均不存在, copied from 11 to 15
{Copy-item-path "d:\11 Annual Information summary \ $a"-recurse-destination d:\15 Year Information summary
Write-host "Find new documents in 11 information summary $a 11 and copy to 15 information summary"
$a 111 = "New file found in 11 information summary $a 11 and copied to 15 information summary"
$a 111| Out-file "D:\15 Annual Information summary \ Copy file log. txt"-append-encoding UTF8 #输出到日志, easy to compare
}
}

$total 15=get-childitem "d:\15 Annual Information Summary" | foreach {$_.name} #因为15年文件夹已更新, so you need to find it again
foreach ($a in $total 12)
{
if ($a 12-notin $total) #假如12年的文件夹里面的文件在15年文件夹里面均不存在, copied from 12 to

{Copy-item-path "d:\12 Annual Information summary \ $a"-recurse-destination d:\15 Annual Information summary
Write-host "Find new documents in 12 information summary $a 12 and copy to 15 information summary"
$a 222 = "New file found in 12 information summary $a 12 and copied to 15 information summary"
$a 222| Out-file "D:\15 Annual Information summary \ Copy file log. txt"-append-encoding UTF8 #输出到日志, easy to compare }
}

$total 15=get-childitem "d:\15 Annual Information Summary" | foreach {$_.name} #因为15年文件夹已更新, so you need to find it again
foreach ($a in $total 13)
{
if ($a 13-notin $total) #假如13年的文件夹里面的文件在15年文件夹里面均不存在, copied from 13 to

{Copy-item-path "d:\13 Annual Information summary \ $a"-recurse-destination d:\15 Year Information summary
Write-host "Find new documents in 13 information summary $a 13 and copy to 15 information summary"
$a 333 = "New file found in 13 information summary $a 13 and copied to 15 information summary"
$a 333| Out-file "D:\15 Annual Information summary \ Copy file log. txt"-append-encoding UTF8 #输出到日志, easy to compare

}
}

$total 15=get-childitem "d:\15 Annual Information Summary" | foreach {$_.name} #因为15年文件夹已更新, so you need to find it again
foreach ($a in $total 14)
{
if ($a 14-notin $total) #假如14年的文件夹里面的文件在15年文件夹里面均不存在, copied from 14 to

{Copy-item-path "d:\14 Annual Information summary \ $a"-recurse-destination d:\15 Annual Information Material summary
Write-host "Find new documents in 14 information summary $a 14 and copy to 15 information summary"
$a 444 = "New file found in 14 information summary $a 14 and copied to 15 information summary"
$a 444| Out-file "D:\15 Annual Information summary \ Copy file log. txt"-append-encoding UTF8 #输出到日志, easy to compare

}
}

Step 3, after the final effect is as follows:

650) this.width=650; "Width=" "height=" 993 "title=" 11.png "style=" Width:728px;height:467px;float:none; "alt=" Wkiom1tcivbdgoynaa8dhh6aqdy909.jpg "src=" Http://s3.51cto.com/wyfs02/M00/59/B7/wKiom1TciVbDgOynAA8dhh6AqDY909.jpg "/>

650) this.width=650; "Width=" 1146 "height=" 651 "title=" 22.png "style=" Width:727px;height:511px;float:none; "alt=" Wkiol1tcik6bd-vvaahnvr1cr7m320.jpg "src=" Http://s3.51cto.com/wyfs02/M01/59/B4/wKioL1Tcik6Bd-vVAAhnVR1cr7M320.jpg "/>

This article is from the "Zhou Ping Microsoft Technology Exchange Platform" blog, please be sure to keep this source http://yuntcloud.blog.51cto.com/1173839/1614132

PowerShell Management Series (21) file merging in different folders of PowerShell operation

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.