加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Powershell 初探

发布时间:2020-12-16 02:16:41 所属栏目:百科 来源:网络整理
导读:最近从一名前端程序员转行到了数据库方面,并首次接触到了Power Shell这一工具 现在有这样的需求,在某个目录下有其他程序生成的dtsx文件,需要有选择地把它们拷贝到部署目录下面 需要拷贝的文件列表写在xml文件里 形式如下: batch add filepath = "test.tx

最近从一名前端程序员转行到了数据库方面,并首次接触到了Power Shell这一工具
现在有这样的需求,在某个目录下有其他程序生成的dtsx文件,需要有选择地把它们拷贝到部署目录下面
需要拷贝的文件列表写在xml文件里
形式如下:

<batch>
    <add filepath="test.txt" virtualPath="PositionRisk" />
    <add filepath="test1.txt" virtualPath="PositionRisk" />
    <add filepath="test2.txt" virtualPath="PositionRisk" />
</batch>

filepath属性表示目录下文件名,virtualPath表示目标路径下的子文件夹
完整代码如下

$scriptPath=$MyInvocation.MyCommand.Definition | split-path;
$rootPath ="$scriptPath....." | convert-path $deployConfigPath="$scriptPath.deployment.config" $deployPath = "C:UserslikaiboyDesktopdesetlPositionRisk" if(test-path $deployPath){ remove-item $deployPath -Force -Recurse } new-item -path "C:UserslikaiboyDesktopdesetl" -name "PositionRisk" -type directory $doc=new-object System.xml.XmlDocument $doc.load($deployConfigPath) $root=$doc.DocumentElement $fileNodes=$root.SelectNodes("//add") function CopyFile($item,$desPath){ copy-item -Path $item -Destination $desPath } for($i=0 ;$i -lt $fileNodes.Count ;$i++){ $fileName = $fileNodes.item($i).filepath $filePath = "$rootPathinstallPositionRisk$fileName" $virtualPathAttr =$fileNodes.item($i).virtualPath $virtualPath = "C:UserslikaiboyDesktopdesetl$virtualPathAttr" if( (test-path $filePath) -and (test-path $virtualPath)){ CopyFile $filePath $virtualPath }else{ "source file do not exists" } } 

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读