报告具有特定子文件夹的文件夹

编程入门 行业动态 更新时间:2024-10-27 20:27:46
本文介绍了报告具有特定子文件夹的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在构建一个脚本,该脚本用于将文件部署到多个特定的文件夹. 使用此部分收集目标文件夹.

I am building a script which I use to deploy files to multiple specific folders. The destination folders are collected using this part.

$destinations = Get-ChildItem "C:\this\is\*\my\path\"

因此,仅当文件夹包含子文件夹"\ my \ path \"时,我的脚本才会替换

So my script replaces only if the folder has the subfolders "\my\path\"

如果现在检查我的变量,它将返回完整路径,但是我只需要文件夹名称.我尝试使用select -path至少仅显示路径,但它也返回长度,模式等.

If I now check my variable it will return the fullpathes but I only need the folder name. I tried using select -path to show at least only the path but it returned as well the length, mode etc.

我的目标是仅返回这样的值:

my goal is to return only values like this:

folder 1 folder 2 folder 3

我正在使用Powershell 3.0

I am using powershell 3.0

推荐答案

因此,如果我们要检查具有子结构folder1\folder2的文件夹,其中父文件夹位于C:\Temp中,那么我们将执行以下操作:

So if we are checking for folders that have the child structure folder1\folder2 where the parent folder is in C:\Temp then we would do something like this:

$destinations = (Get-Item "C:\Temp\*\folder1\folder2").Parent.Parent.Name

Get-Item "C:\Temp\*\folder1\folder2"只会为folder2返回System.IO.DirectoryInfo个对象.我们拿走那些对象,找到它们的祖父母文件夹,只返回它们的名字.

Get-Item "C:\Temp\*\folder1\folder2" would just return System.IO.DirectoryInfo objects for folder2. We take those objects and find their grandparent folders and just return their names only.

更多推荐

报告具有特定子文件夹的文件夹

本文发布于:2023-10-31 16:48:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546688.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件夹   报告

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!