首页 > 其他 > 详细

totalcommand + powershell 实现自动替换选定文件

时间:2014-02-17 08:10:01      阅读:584      评论:0      收藏:0      [点我收藏+]

 

研究了powershell一个星期,想写点东西练练手。工作中经常需要将文件从美术目录拷贝到程序目录,全部复制不合适,因为经常有许多美术资源是你不想要同步的。所以需要一个方便的手动选择+自动拷贝流程,totalcommand的命令+powershell 刚好能很好的实现这个需求

实现步骤:

1.total commander 自定义命令设置

这个可以在网上搜索到很多,比如http://fanhongtao.org/2012/12/19/add-user-command-in-tc.html

我就不累述了,直接贴我的usercmd.ini文件:

bubuko.com,布布扣
[em_synfile]
button=
cmd=powershell.exe
param="D:\work\powershell\syn.ps1 %P%S "
bubuko.com,布布扣

该命令是将选定的所有文件路径都传给powershell脚本 syn.ps1,请把D:\work\powershell\替换成你本地的路径

 

2.syn.ps1脚本

 

bubuko.com,布布扣
#source是源目录 target是目标目录
$source
= ‘D:\test2‘ $target = ‘D:\test‘ foreach ($fullname in $args) { $item = Get-Item $fullname
   ##取得相对路径
Set-Location $target $relativePath = $item | Resolve-Path -Relative $sourcefilepath = Join-Path $source $relativePath -resolve
   ##拷贝
if(Test-Path $sourcefilepath) { Write-Host("COPY " + $sourcefilepath + " -> " + $fullname) Copy-Item $sourcefilepath -Destination $fullname } else { Write-Host("ERROR:can‘t find " + $sourcefilepath) } } Write-Host("DONE ") Start-Sleep -s 1
bubuko.com,布布扣

 

以上两步都配置好后,在total commander中选择文件后按你设置的快捷键就可以方便的自动替换文件了

 

bubuko.com,布布扣

totalcommand + powershell 实现自动替换选定文件

原文:http://www.cnblogs.com/redeye821/p/3551680.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!