首页 > 解决方案 > 从 Excel 列表中提取文件

问题描述

我在 excel 中有一个文件列表(该列表由 100 个图像文件名组成),以及一个包含 1000 个图像(实际图像)的文件夹,其中 100 个在 excel 列表中。根据 excel 中的列表,我如何将这 100 张图像移动/复制到新文件夹中?

标签: exceldirectoryoperating-systemextract

解决方案


您可以运行 powershell 脚本(我假设您使用的是 windows)从单元格中提取数据,然后从一条路径移动到另一条路径。以下脚本应该对您的 xlsx 文件名和路径进行一些修改后对您有用。

$endRow= 100 #this is the last row of image locations
$col = "A"
$newPath = "C:\Users\evolve\Documents\imgFolder\"


$excel = New-Object -Com Excel.Application
$workBook = $excel.Workbooks.Open("C:\Users\evolve\Documents\takeoff.xlsx")
$workSheet = $workBook.sheets.item("sheet1")


#different methods can be used to get the outcome you want.

#cycle through the rows of data
for($i = 1; $i -le $endRow; $i++)
{
    $loc = $col + $i
    $imgPath = $workSheet.Range($loc).Text
    
    #extract the actual filename
    
    $split = $imgPath.split("\")
    $imgName=[string]$split[($split.count-1)] 
    
    $newImgLocation = $newPath + $imgName
    
    #move the image to the new folder
    Move-Item $imgPath $newImgLocation
    
    
}

推荐阅读