Chinaunix首页 | 论坛 | 博客
  • 博客访问: 535983
  • 博文数量: 53
  • 博客积分: 6801
  • 博客等级: 少将
  • 技术积分: 1575
  • 用 户 组: 普通用户
  • 注册时间: 2004-10-04 11:00
个人简介

:)

文章分类

全部博文(53)

文章存档

2010年(4)

2009年(16)

2008年(33)

分类: WINDOWS

2009-10-08 21:27:41


#===========================

#

#Name:

#Author:PopZslam

#Description:

#Version:

#

#===========================



param(
    [String]$LOCAL:sourceDirectory=$input,
    [String]$LOCAL:destinationDirectory=$(Get-Location)
)

#===========================

#    Variables

#===========================


$LOCAL:notifyMessage=@(
    "请指定一个目录名。",
    "请指定目标目录名。",
    "您指定的参数不是目录:$LOCAL:sourceDirectory",
    "目标磁盘没有足够的剩余空间。",
    "您提供的参数不完整。"
)

$LOCAL:destinationDirectorySize=0
$LOCAL:sourceDirectorySize=0
$LOCAL:newName=""
$LOCAL:prefixString=""
#===========================

#    Functions

#===========================


function    get-freespace
{
    param([string]$LOCAL:destinationDirectory=(get-location))
    if($LOCAL:destinationDirectory.Trim() -eq ""){
        $LOCAL:destinationDirectory=(Get-Location);
    }
    
    $LOCAL:driveLeter=split-path -Path "$LOCAL:destinationDirectory" -qualifier
    $LOCAL:t=Get-WmiObject -Class Win32_LogicalDisk -Filter "DeviceID='$LOCAL:driveLeter'"
    foreach ($_ in $LOCAL:t){
        return $_.freespace
    }
}

#===========================

#    Main Part

#===========================


# Check the parameter

if((($LOCAL:sourceDirectory).trim() -eq "") ){
    $LOCAL:notifyMessage[4]
    "command -source -destination"
    "command -source 'c:\source' -destination 'd:\destination'"
    exit
}

$LOCAL:destinationDirectorySize=get-freespace($LOCAL:destinationDirectory)

if (Test-Path -Path $LOCAL:sourceDirectory -PathType Container){
    $LOCAL:sourceDirectorySize=(Get-ChildItem -Force -Recurse -Path $LOCAL:sourceDirectory|Measure-Object -Property length -Sum).sum
    if ($LOCAL:sourceDirectorySize -ile $LOCAL:destinationDirectorySize){
        foreach ($_ in (Get-ChildItem -Force -Recurse -Path $LOCAL:sourceDirectory) ){
            if (Test-Path -Path $_.fullname -PathType Leaf){
                $LOCAL:prefixString=Split-Path -Path $_.fullname -Parent |Split-Path -Leaf;
                $LOCAL:newName=$LOCAL:prefixString+"-"+$_.name
                Copy-Item -Path $_.fullname -Destination $LOCAL:destinationDirectory\$LOCAL:newName
            }
        }
    }else{
        throw $LOCAL:notifyMessage[3]
    }
}else{
    throw $LOCAL:notifyMessage[2]
}


阅读(1494) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~