4

So I just want to know if there's a way that I can get the name of the directory or a folder.

So for example I have these folders in my directory

test1_ew test2_ter test3_ew

So I just want to get the folders that have "_ew" on their names. So basically I want to check all the folder names in my current directory if there's a _ew on their names.

If such folder(s) exist, I would like to run an executable file inside the folder(s).

Thank you in Advance!

3
  • You need to add a few more specifics. What language are you using? Commented Jan 7, 2015 at 22:33
  • I've added the CMD tag for you and added the full requirements of your question to make it clear for others. Commented Jan 7, 2015 at 22:45
  • Thank you bro, this is also my first time to use SO Commented Jan 7, 2015 at 22:46

2 Answers 2

1

Why not use IF EXIST if the text you are looking for will not change?

Here's an example:

C:\Scripts>for /f %a in ('dir c:\scripts\*s* /b /A:D') do echo %a C:\Scripts>echo sccm sccm C:\Scripts>echo Test Test C:\Scripts>echo updates updates 

-Edit to add IF EXIST

C:\Scripts>for /f %a in ('dir c:\scripts\*s* /b /A:D') do if exist %a echo YES C:\Scripts>if exist sccm echo YES YES C:\Scripts>if exist Test echo YES YES C:\Scripts>if exist updates echo YES YES 
Sign up to request clarification or add additional context in comments.

Comments

0

You can use the Attribute switch /A: with the DIR command to specify you only want to look for a directory and use a wildcard for the directory name:

DIR C:\FOLDER\*_ew /B /A:D 

You could also send this to a text file, for example on your desktop, like so:

DIR C:\FOLDER\*_ew /B /A:D > %USERPROFILE%\Desktop\TEST_OUTOUT.txt 

note that if any of the paths used have spaces you will need to wrap them in quotation marks.

10 Comments

I need some more help. I want that if I found a folder that containing _ew on their name. I want to have a If statement that, if found _ew then will open a executable file. I'm sorry this is my first encounter batch scripts What I have now is this one for /d /r "E:\tester" %%i in (.) do if /i "%%~nxi"=="ew" set "folderpath=%%i" ( echo %folderpath% )
Will all of the _ew directories have an exe file in them? and what will the exe file be called? - or do you mean that if the directory exists that you want to a run a separate exe file saved somewhere else?
No, I think im totally lost now. Give me a moment. Sorry
Actually bro, I have this script that finding a Stuck files with "FALSE" string with their names (not in their file names or directory name) STRING name. I already did this and, what I want is, all those have "FALSE" string on their names is I want to get and move them into another directory and ALL THOSE FILES is have different extensions. I hope you'll get my point.
Not really - I'm not sure what you mean when you say that "FALSE" is in their String name and not in their actual filename?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.