Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 554 Vote(s) - 3.44 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Batch Script to Find a Folder inside Sub Folders and get Folder Path

#1
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.
Reply

#2

@echo off
for /d /r "c:\temp" %%a in (*) do if /i "%%~nxa"=="apples" set "folderpath=%%a"
echo "%folderpath%"
Reply

#3
breaking down [foxidrive's answer][1]

> @echo off
> for /d /r "c:\temp" %%a in (*) do if /i "%%~nxa"=="apples" set "folderpath=%%a"`
> echo "%folderpath%"`

## for loop arguments

for /d /r "c:\temp" %%a in (*) do

**/d** indicates search for folders (**D**irectories) in a folder set

**/r** indicates search for files **R**ooted in a specific path. In foxidrives's example it's "c:\temp". The /r argument also expects a set of files as the condition for the for loop. e.g.

for ... (file1.*, another?.log)
but in this case, we use wildcard (*) to look at everything

## IF

if /i "%%~nxa"=="apples"

**/i** indicates to **i**gnore character chase when comparing the strings

**%%~na** indicates to expand %%a *without* the full path

**%%~xa** indicates to expand %%a without a file extension (e.g. .zip, .cmd, .exe). Although, to me, this seems redundant since we already specified /d (directories only) in the for section.

therefore, **%%~nxa** shows *just* the folder name, deleting extension and full path. For example, if you had C:\some\path\myfile.ext in %%a, then %%~nxa would expand to myfile

### Sources

<https://ss64.com/nt/for.html>

<https://ss64.com/nt/for_r.html>

<https://ss64.com/nt/syntax-args.html>


[1]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
2 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through