43 lines
2.0 KiB
Python
Executable File
43 lines
2.0 KiB
Python
Executable File
import os
|
|
from openpyxl import load_workbook
|
|
from tqdm import tqdm
|
|
# Define the base path for the dataset
|
|
audio_base_path = "/data5/Temp_ProjectData/QiJianProject/2022ZD0116304-202405/Videos/VFGR/"
|
|
|
|
# Load the Excel workbook and select the active sheet
|
|
workbook_path = "/data1/Hatcher/model/project/MPKFNet/大规模数据库-视频.xlsx" # Update this with the actual path to the Excel file
|
|
workbook = load_workbook(workbook_path)
|
|
sheet = workbook.active # Assuming the active sheet is the one we need
|
|
|
|
# Function to update the Excel with new audio data
|
|
def update_excel_with_audio_data(base_path, sheet):
|
|
# Find the last row with data to continue from there
|
|
last_row = sheet.max_row + 1
|
|
a = 0
|
|
# Iterate through all subfolders in the base directory
|
|
for folder_name in tqdm(os.listdir(base_path)):
|
|
folder_path = os.path.join(base_path, folder_name)
|
|
# a=a+1
|
|
# if a>2:
|
|
# break
|
|
if os.path.isdir(folder_path): # Ensure it's a directory
|
|
# Iterate through all audio files in the folder
|
|
|
|
for audio_name in os.listdir(folder_path):
|
|
if audio_name.lower().endswith(('.mp4')): # Check audio extensions
|
|
audio_path = os.path.join(folder_path, audio_name)
|
|
|
|
# Fill the Excel sheet
|
|
sheet.cell(row=last_row, column=1, value=last_row - 1) # Sequence number
|
|
sheet.cell(row=last_row, column=2, value=audio_path) # Audio data
|
|
sheet.cell(row=last_row, column=3, value=folder_name) # Label (folder name)
|
|
sheet.cell(row=last_row, column=4, value=0) # Data function type is always 1
|
|
|
|
# Increment the row index for the next entry
|
|
last_row += 1
|
|
|
|
# Save the updated workbook
|
|
workbook.save(workbook_path) # Save the changes to the same file
|
|
|
|
# Uncomment the following line to run the function with actual file paths in a real environment
|
|
update_excel_with_audio_data(audio_base_path, sheet) |