Wie kann ich Dateien im Verzeichnis mit Dateinamen in Textdateien oder Excel-Tabellen vergleichen und filtern?

1636
AZUZ

Ich habe 100000 mp3-Dateien in einem Verzeichnis, jede Datei enthält einen zufälligen Dateinamen und ich habe ein anderes Excel-Blatt, das den Namen der mp3-Datei enthält und an den sie zugeordnet ist. Gibt es eine Möglichkeit, ein Skript zu entwickeln, oder Software von Drittanbietern kann dabei helfen, diese Dateien in 3 verschiedene Ordner zu kategorisieren

Beispiel:

  • Im Verzeichnis

Datei wie: fasf4a5465.mp3, fasdf35434.mp3, vefbgwsbgg.mp3

  • In der Excel

    1. Spalte 1: Dateiname = fasf4a5465.mp3, Spalte 2 'Dateigruppe' = Gruppe1
    2. Spalte 1: Dateiname = fasdf35434.mp3, Spalte 2 'Dateigruppe' = Gruppe2
    3. Spalte 1: Dateiname = vefbgwsbgg.mp3, Spalte 2 'Dateigruppe' = Gruppe3

Meine endgültige Ausgabe besteht also aus drei verschiedenen Ordnern (Gruppe 1, Gruppe 2, Gruppe 3). Die 100000 werden nach Excel-Mappings kategorisiert

Da ich viele Mp3-Dateien habe, ist es schwierig, auf jede einzelne zu hören und sie manuell zu kategorisieren. Ich brauche also eine Möglichkeit, sie zu vergleichen und an einem anderen Ort abzulegen

Irgendwelche Problemumgehung dafür?

3
Zur Klarheit. Sie haben bereits die genauen Dateinamen in einer Liste und benennen die Gruppe, in der Sie sie haben möchten. Richtig? Wenn ich Sie also bat, drei Listen zu erstellen, kopieren Sie group1 und vorherige in eine Notepad-Datei und speichern Sie sie als group1.txt. Alle Namen in dieser Liste wären für Ihren gewünschten Ordner, ja? Können Sie eine Excel-Tabelle kopieren und an ihr vorbeiziehen, um besser zu verstehen, mit was es zu arbeiten gibt? Die Lösung könnte darin bestehen, eine Formel zu erstellen, um die Liste in mehrere verschiedene Listen zu unterteilen, und dann mithilfe der Programmierung Ordner erstellen und in diesen Ordner verschieben. ejbytes vor 8 Jahren 1

1 Antwort auf die Frage

1
Pimp Juice IT

I have 100000 mp3 files in one directory, each file contain a random filename, and I have another excel sheet containing the mp3 file's name and to whom it maps to. Is there any way to develop a script or 3rd party software can help categorize these files into 3 different folder

  • In the Excel

    1. Column 1: File name = fasf4a5465.mp3, Column 2 'File Group' = Group1
    2. Column 1: File name = fasdf35434.mp3, Column 2 'File Group' = Group2
    3. Column 1: File name = vefbgwsbgg.mp3, Column 2 'File Group' = Group3

Okay, so it's a script you want to do this then Powershell to the rescue with the below logic.

PowerShell Script Variables Explained

  • $ExcelFile =
    • You will need to make this variable point to your XLS or XLSX file (yes either one will work) which contains the mappings, or the column values per row which the first column is the MP3 file name and the second column is the group name or the new subfolders these files will be copied to.
  • $CSVFile =
    • You will need to make this variable point to the CSV converted temporary file (based on what's in the Excel ($ExcelFile)) for the rest of the logic to do it's magic. If this file already exists, I put the logic to overwrite it so no worries on a static file name.
  • $MP3SourceDir =
    • You will need to make this variable point to your MP3 source directory where these file will be grabbed from initially based on the file names from first column in the Excel spreadsheet. Warning: you MUST keep the \$($_.first) logic in this logic—just plug in the other path part only.
  • $NewMP3Dir =
    • You will need to make this variable point to the new location where the new [group] second column folders will be created for the applicable first column MP3 files to be copied. Warning: you MUST keep the \$($_.second) logic in this logic—just plug in the other path part only.

PowerShell Script Example

$ExcelFile = "C:\Path\Excel Worksheet.xlsx" $CSVFile = "C:\Path\ExportCSV.csv" $Excel = New-Object -ComObject excel.application $Excel.visible = $False $Excel.displayalerts = $False $WorkBook = $Excel.Workbooks.Open("$ExcelFile") $WorkSheet = $Workbook.worksheets.Item(1) If (Test-Path $CSVFile){ Remove-Item $CSVFile } $WorkBook.SaveAs("$CSVFile", 6) $Excel.quit() Import-Csv "$CSVFile" -Header ("first","second") | ForEach { $MP3SourceDir = "D:\Path\SourceMP3\$($_.first)" $NewMP3Dir = "D:\Path\NewMP3\$($_.second)" New-Item -ItemType Dir "$NewMP3Dir" -Force Copy-Item "$MP3SourceDir" -Destination "$NewMP3Dir\$($_.first)" -Force } 

(Note this is the source I got the logic idea from for the xls to csv conversion to then read the delimited values in the csv file to then do the rest so I made many adjustments as well)

(This script essentially takes an existing XLS or XLSX file with two column [mapping] values in column A and column B (all rows), and saves it in CSV format to another CSV file. It then reads from that CSV file and the CSV value of column A (per line or row) is used as the file name to copy to another folder (or subfolder), which is the column B CSV value (on the same line or row). Each line or row should contain two values with the first being a file name and the second being a folder name—these are the values looped through running the commands to copy, etc.)

Source: PowerShell XLS to CSV


Further PowerShell Command Reading

@AZUZ Bitte teilen Sie mir mit, ob meine Antwort zur Lösung Ihres Problems beigetragen hat, und lesen Sie auch [** Accepting Answer **] (http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer) -work), um sicherzustellen, dass Sie wissen, wie diese Website mit Fragen und Antworten funktioniert, um die Schleife Ihrer Fragen zu schließen und eine Antwort zu erhalten, die zum Lösen Ihrer Probleme geeignet ist. Es ist so einfach, das Häkchen neben der Antwort zu markieren, die Ihr Problem löst. Pimp Juice IT vor 8 Jahren 0