我有以下Power Shell脚本需要修改。
$filepath = "F:feedsAmazon"
$temppath = $filepath+"temp.csv"
$files = ls -Path $filepath *.csv
foreach ($file in $files){
gc $file.FullName |
% { if($_.indexOf("|~|") -eq -1) {$_ -replace "`"((?:`"`"|.)*?)`"(?!`")", "|~|`$1|~|" -replace "`"`"", "`""} else {$_ -replace " ", " "}} |
sc $temppath
ri $file.fullName
rni -Path $temppath -NewName $file.fullName
}
此脚本遍历定义文件夹中的所有.csv文件并更改文本限定符。现在我需要稍微改变一下,我被卡住了。
基本上我的CSV文件被分散到多个文件夹,比如。亚马逊1、亚马逊2、亚马逊3……等等。有没有通配符匹配之类的东西能让它查找所有以Amazon开头的文件夹?
我不想循环遍历文件夹
…*
字符?试试这个:
$filepath = "F:feedsAmazon*"
$files = ls -Path $filepath *.csv -recurse
foreach ($file in $files){
$temppath = $file.directoryName+"temp.csv"
gc $file.FullName |
% { if($_.indexOf("|~|") -eq -1) {$_ -replace "`"((?:`"`"|.)*?)`"(?!`")", "|~|`$1|~|" -replace "`"`"", "`""} else {$_ -replace " ", " "}} |
sc $temppath
ri $file.fullName
rni -Path $temppath -NewName $file.fullName
}
是使用Get-child-Item
Cmdlet (dir)您可以在文件夹上使用通配符匹配:
Get-ChildItem "C:tempAmazon?" -include *.csv -Recurse