[英]Powershell: find files based on directory name, copy and rename into same folder and keep original
I am migrating to a new Movie/DVD/BluRay management systems, and need to take existing cover art that is named based on the directory name (directoryname.jpg), copy and name the new files folder.jpg and mymovies-front.jpg. 我正在迁移到新的Movie / DVD / BluRay管理系统,并且需要采用基于目录名(directoryname.jpg)命名的现有封面,复制并命名新文件folder.jpg和mymovies-front.jpg 。 I also need to keep the original file in place. 我还需要保留原始文件。
## Q:\Test\2017\07\14\SO_45110819.ps1
Set-Location "X:\path\to\base"
Get-ChildItem * | Where-Object {$_.PSIsContainer}|ForEach-Object {
$dirnamejpg = Join-Path $_.FullName ($_.BaseName+'.jpg')
if (Test-Path ($dirnamejpg)) {
copy-Item -Path $dirnamejpg -Destination (Join-Path $_.FullName ('folder.jpg')) -confirm
copy-Item -Path $dirnamejpg -Destination (Join-Path $_.FullName ('mymovies-front.jpg')) -confirm
}
}
Once the actions performed are OK, remove the -confirm
parameter 一旦执行的操作正常,请删除-confirm
参数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.