我創建了一個腳本,該腳本從特定目錄中的每個 .mp4 檔案中獲取Name
,CreationTime
然后使用 Cmdlet 將資料匯出到 CSV 檔案中。Duration
Export-Csv
現在我有 3 個 CSV 匯出,我想合并它們,所以我嘗試了這個:
$Data = @()
$CSVsPaths | ForEach-Object {
$Data = Import-Csv -Path "$_" -Encoding "UTF8"
}
$Data
但由于某種原因,一些物件是重復的,我確信匯出都包含不同的資料。我究竟做錯了什么?
編輯:
以下是 CSV:https ://drive.google.com/drive/folders/1MbeUenLxbKdlle6rKFwc3jJNZf85AMtd
uj5u.com熱心網友回復:
如評論中所述,您的輸出具有重復的行,因為您的資料集中已經存在重復行。
要定位重復的行,Get-Content
請針對輸入檔案使用 - 檔案系統提供程式會將一些隱藏的屬性附加到輸出中,我們可以稍后使用這些屬性來識別重復的位置:
# find all non-unique strings in the input files
$nonUniques = Get-Content '.\Export*.csv' |Group-Object |Where-Object Count -gt 1 |ForEach-Object Group
# use the PSChildName and ReadCount provider properties to identify the files that host the duplicate content,
# then use Format-Table to show output nicely grouped on the non-unique string value
$nonUniques |Select @{Name='Name';Expression='PSChildName'},@{Name='Line';Expression='ReadCount'},@{Name='Duplicate';Expression={$_}} |Format-Table Name,Line -GroupBy Duplicate
給定您鏈接的輸入資料,它將產生如下內容:
Duplicate: "QVR_06082021_141022 (PRIMA VOLTA CHE REGISTRO).mp4","06/08/2021 14:10:22","00:00:46"
Name Line
---- ----
Export 2 (da 24-06-2022 a 31-07-2022).csv 113
Export 3 (da 06-08-2021 a 31-08-2021).csv 3
Duplicate: "QVR_06082021_142308.mp4","06/08/2021 14:23:08","00:00:50"
Name Line
---- ----
Export 2 (da 24-06-2022 a 31-07-2022).csv 114
Export 3 (da 06-08-2021 a 31-08-2021).csv 4
Duplicate: "VID_20210806_220220.mp4","06/08/2021 22:02:20","00:00:20"
Name Line
---- ----
Export 2 (da 24-06-2022 a 31-07-2022).csv 115
Export 3 (da 06-08-2021 a 31-08-2021).csv 5
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/504258.html