create a script for windows to search all files, folders, and subfolders for a string…
- 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
- 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! pauseSave the file with a
.batextension, 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 /rline with a specific path, like this:for /r "C:\path\to\search" %%A in (*) do (
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.