简体   繁体   English

如何从文件列表中获取完整路径?

[英]How to get full path from a list of files?

I have a csv file looks like this: 我有一个csv文件,看起来像这样:

foo.html,9,0
bar.html,0,3
otherfile.html,9,1

Every row in this csv file, contains a filename. 此csv文件中的每一行都包含一个文件名。 I need to replace the filename with the fullpath of this filename. 我需要用该文件名的完整路径替换文件名。

for example, foo.html should be replace with c:\\somefolder\\sub\\sub\\foo.html . 例如, foo.html应该替换为c:\\somefolder\\sub\\sub\\foo.html

  • I know that all the files are somewhere inside c:\\somefolder . 我知道所有文件都在c:\\somefolder内部。

How to do that with Powershell ? 如何使用Powershell做到这一点?

Following your comment that you know how to get the names from the csv and know that the files are in the the folder C:\\somefolder you can try to loop this: 根据您的评论,您知道如何从csv获取名称,并且知道文件位于文件夹C:\\somefolder ,可以尝试循环执行此操作:

$allItems = Get-ChildItem -Recurse C:\somefolder
$fullname = @()

foreach ($item in $itemsFromCsv)
{
  $fullname += $a | Where-Object {$_.Name -eq $file} | Select-Object -ExpandProperty Fullname
}

This searches you the Fullname (path + Name) and saves it in the array $fullname . 这将搜索您的全名(路径+名称),并将其保存在数组$fullname You can then add the array to your csv and export it. 然后,您可以将数组添加到csv并将其导出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM