Skip to content
The Chat Archive
gpt-4-0613· OpenAI Arena Human Preference 55K

Hi, can you write a batch script for Windows that will scan all subdirectories in the…

  1. User

    Hi, can you write a batch script for Windows that will scan all subdirectories in the existing folder looking for directories that are either empty or contain only files that are not audio files? I need to find all folders that have only images or text files, for example. Any folders containing any audio files should be ignored (.mp3, .m4a, .flac, .opus, .wav). I don't want to edit the script, just double click to run it. The results should list each path to the folders in question, exported as a single text file in the same directory that the script is ran from. Thanks!

  2. Assistant

    Sure, this should do what you need.

    Here is a simple batch script that will go through each directory and sub-directory, check if there are any audio files and if not, it checks if the directory is empty. If it passes these criteria, it will add the directory to a txt file.

    @echo off
    setlocal enabledelayedexpansion
    
    :: List of audio file extensions
    set "audioExts=.mp3 .m4a .flac .opus .wav"
    
    :: Output file name
    set "outputFile=nonAudioDirs.txt"
    
    :: Delete output file from previous runs
    if exist "%~dp0%outputFile%" del "%~dp0%outputFile%"
    
    :: Scan directories
    for /r /d %%D in (*) do (
        set "hasAudio=0"
        for %%F in (%%D\*) do (
            for %%E in (%audioExts%) do (
                if "%%~xF"=="%%E" (
                    set "hasAudio=1"
                    goto :NextDir
                )
            )
        )
        if !hasAudio! equ 0 (
            if not exist "%%D\*" (
                echo %%D>>"%~dp0%outputFile%"
            )
        )
        :NextDir
    )
    
    echo Done!
    pause
    

    Remember to save this with a .bat or .cmd extension. Double-clicking the saved file will run the script and create a text file in the same directory, listing all the paths to directories that contain only non-audio files or no files at all.

    Please note that this script might take some time to execute if there are a lot of subdirectories or files to check.

    Let me know if you need any modifications.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.