Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch Script to Find a Folder inside Sub Folders and get Folder Path

Tags:

batch-file

I am trying to come up with a batch file that will perform the following:

  1. Ask the user to input a name. If no name was given, ask again.
  2. Search all sub folders from a starting point (say C:\Temp) for that name.
  3. If found, I then want to move that found folder and all it's contents to another directory.
  4. If not found, let the user know it wasnt found and allow them to try again or the application.

I am not having much luck finding an example of such a script or bits and pieces of it even to put something together.

like image 816
PY_ Avatar asked Jul 18 '13 13:07

PY_


People also ask

How do I search for a file in a subfolder?

To search for files in File Explorer, open File Explorer and use the search box to the right of the address bar. Tap or click to open File Explorer. Search looks in all folders and subfolders within the library or folder you're viewing.

Does path include subfolders?

The PATH variable would only contain the folder, not its subdirectories (desired result). 3. Invoking program. bat as %PATH%\program.

What is path in batch file?

The Path variable holds the names of folders that are searched if the file being executed is not in the default folder at the command prompt. For example, if all the batch files are in C:\BATCH, and c:\batch is added to the Path environment variable, that batch file can be run from any command prompt.


1 Answers

@echo off
for /d /r "c:\temp" %%a in (*) do if /i "%%~nxa"=="apples" set "folderpath=%%a"
echo "%folderpath%"
like image 139
foxidrive Avatar answered Nov 11 '22 22:11

foxidrive