2

So I have a batch file that checks for files in a directory against 4 different file extensions and processes them if they have the correct file extension:

set count=0
for %%x in (*.J_E, *.J_T, *.J_I, *.BCC) do (
  set /a count=count+1
  set choice[!count!]=%%x
)
for /l %%x in (1,1,!count!) do (
   echo %%x. !choice[%%x]!
   tlv2txt !choice[%%x]! > !choice[%%x]!.txt
)

What I would like to do is add the ability to also use files where the filename contains a certain string like 'marmite'. For example..

By running the batch file I would be looking to 'process' the files marked with an asterisk only:

  • stuff.j_e *
  • Things.j_t*
  • MoreStuff.j_i *
  • SomeThings.txt
  • SomeMarmiteInA.jar *
  • NotThisFile.jim
  • OrThisOne.txt
  • ThisOneThough.bcc*
  • marmiteOnToast.tlv*

Like I said, I can get the file extensions, but I haven't the foggiest idea how to get filenames that contain.. Is this do-able?

3
  • Well, I seem to have answered my own question. I'll leave the answer here for anyone else who might be experiencing the same problem.. The answer is *marmite*.* So, using the example above; for %%x in (*.J_E, *.J_T, *.J_I, *.BCC, *marmite*.*) Hope this helps someone! :) Commented May 5, 2016 at 10:55
  • You could post this as an answer and then even accept it, so tge question does no longer appear open... Commented May 5, 2016 at 11:28
  • Thanks aschipfl - done now.. :) Commented May 5, 2016 at 11:43

2 Answers 2

2

Well, I seem to have answered my own question!

I'll leave the answer here for anyone else who might be experiencing the same problem..

The answer is

*marmite*.* 

So, using the example above;

for %%x in (*.J_E, *.J_T, *.J_I, *.BCC, *marmite*.*) 

Hope this helps someone! :)

Sign up to request clarification or add additional context in comments.

Comments

1

Yes, you can achieve it.

dir /a:-D /b | findstr /i "word"

dir /a:-D /b : This command will list all files in the directory.

findstr /i : This command will check for the matching word in all files and lists them

/i : case insensitive search. In our example, we will get a list of filename which have name containing string "word".

Please take this idea and proceed.

2 Comments

Thanks prudviraj, while useful - it's not quite what I'm after. If I understand this correctly, this will find a string of text INSIDE files, what I was looking for was a FILENAME that contains the string 'marmite' (eg: somemarmite.txt). I have since worked it out and posted the answer that works for me. Thanks for taking the time out anyway!
@Doug this command will get input from dir command and finds the string in the file name. verified from my end.revert if you thinks it is acting different.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.