Skip to content
TheChatArchiveThe Chat Archive
gpt-4-0314· OpenAIHugging Face Arena Human Preference 55K

create a script for windows to search all files, folders, and subfolders for a string…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with gpt-4-1106-preview’s answer.
  1. User

    create a script for windows to search all files, folders, and subfolders for a string that starts "dude" then create a shortcut that points to each in a folder on the desktop called dudefolder

  2. Assistant

    You can create a simple Batch script to achieve this task. Open Notepad or any text editor and paste the following code:

    @echo off
    setlocal enabledelayedexpansion
    
    set "searchString=dude"
    set "outputFolder=%USERPROFILE%\Desktop\dudefolder"
    
    mkdir "!outputFolder!"
    
    for /r %%A in (*) do (
        set "filename=%%~nxA"
        echo !filename! | findstr /b /c:"!searchString!" >nul && (
            echo Found: %%~dpnxA
            echo Creating shortcut in !outputFolder!
            set "shortcut=!outputFolder!\!filename! - Shortcut.lnk"
            echo Set oWS = WScript.CreateObject("WScript.Shell") > CreateShortcut.vbs
            echo sLinkFile = "!shortcut!" >> CreateShortcut.vbs
            echo Set oLink = oWS.CreateShortcut(sLinkFile) >> CreateShortcut.vbs
            echo oLink.TargetPath = "%%~dpnxA" >> CreateShortcut.vbs
            echo oLink.WorkingDirectory = "%%~dpA" >> CreateShortcut.vbs
            echo oLink.Save >> CreateShortcut.vbs
            cscript //nologo CreateShortcut.vbs
            del CreateShortcut.vbs
        )
    )
    
    echo Done!
    pause
    

    Save the file with a .bat extension, for example, search_dude_files.bat. Double-click this file to run the script. It will create a folder called "dudefolder" on your Desktop and create shortcuts for all files, folders, and subfolders starting with "dude" in their name.

    Please note that this script will search for files and folders starting with "dude" in the directory where the script is located and its subdirectories. If you want to search in a specific directory, you can modify the for /r line with a specific path, like this:

    for /r "C:\path\to\search" %%A in (*) do (
    

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