1.

Solve : A problem that's too long to explain in this title?

Answer»

As the title states, my BATCH problem is too long to simply write in the title. I have tried everything and I can't figure out how to do this. So, here's my problem:
I have a program that GENERATES a code, specifically with a STRING of numbers divided by underscores.
(there won't be any strings with matching numbers) Example : 1_2_3_4_5, 2_7_4_9_0 etc. So I have a folder filled with text files with titles containing the same kind of string, none of the strings match. But here's what I would like to do: take a random string like 1_3_5_7_9 and see how many matching numbers the two strings contain. I have tried experimenting with the for command but everything I try fails. This one is more difficult then what I normally do as it requires more extensive knowledge and use of the for command. Quote from: BatchFileCommand on August 13, 2009, 10:12:55 PM

As the title states, my batch problem is too long to simply write in the title. I have tried everything and I can't figure out how to do this. So, here's my problem:
I have a program that generates a code, specifically with a string of numbers divided by underscores.
(there won't be any strings with matching numbers) Example : 1_2_3_4_5, 2_7_4_9_0 etc. So I have a folder filled with text files with titles containing the same kind of string, none of the strings match. But here's what I would like to do: take a random string like 1_3_5_7_9 and see how many matching numbers the two strings contain. I have tried experimenting with the for command but everything I try fails. This one is more difficult then what I normally do as it requires more extensive knowledge and use of the for command.

EH, this is quite complicated,
Batch files need specific dirrections and information to perform opperations,
Just out of pure currosity and to help with this investigation, what exactly is your batch file destined to do? As in its purpose.after reading your essay, i still don't understand what you are trying to do. Give examples and show your final output.Quote from: BatchFileCommand on August 13, 2009, 10:12:55 PM
here's what I would like to do: take a random string like 1_3_5_7_9 and see how many matching numbers the two strings contain.

You want to examine each filename and see if it contains one or more of (for example) 1, 3, 5, 7 or 9?

something like this

need delayed expansion
for blah blah blah %%F in ('dir /b') do
set filename=%%F
for /f "tokens=1-5 delims=_" %%A in ("!filename!") do (
echo !filename! | find "%%A" && echo found %%A
echo !filename! | find "%%B" && echo found %%B
etc
)
)




IF YOU WANT A BETTER DESCRIPTIONG OF WHAT I WANT TO DO SKIP THE FIRST SECTION!

I figured out how to do it!
1, set both strings to variables like %1% and %2%.
and do the following: %1:~0,2% I would set that to a variable like %n1% which stands for number 1.
do the same thing again : set n2=%1:~2,4%
then repeat the process for the other 3 numbers and the second string! Then
using lots of if commands (MAYBE for loops) I would simply see how many numbers match!
_______________________________________ ___________________________________

Okay, so this is what I wanted to do take 2 strings like
1_4_9_2_5
and
5_9_7_5_4
and see how many numbers matched between the two of them. in this case it would be 3.



Discussion

No Comment Found