@echo -off
# 1. Detect drive
for %i in 0 1 2 3 4 5 6 7 8 9 A B C D E F
    # Search for the bootable drive (usually skips FS0 if OS drive differs)
    if exist FS%i:\efi\boot\bootx64.efi then
        # Switch to the identified drive
        FS%i:
        
        # 2. Universal path switching:
        # Check current directory, then parent directory (Project Mode),
        # and finally the root directory (Root Mode) for the BIOS folder.
        
        # Attempt 1: Check if BIOS is in the current directory
        if exist BIOS\Flash.nsh then
            cd BIOS
            Flash.nsh
            goto EXIT
        endif
        
        # Attempt 2: Check if BIOS is in the parent directory (relative to current script)
        cd ..
        if exist BIOS\Flash.nsh then
            cd BIOS
            Flash.nsh
            goto EXIT
        endif
        
        # Attempt 3: Check if BIOS is in the root directory of the drive
        if exist \BIOS\Flash.nsh then
            cd \BIOS
            Flash.nsh
            goto EXIT
        endif
    endif
endfor

:EXIT
echo -on
