Search code examples
batch-filefindsetircbots

This Supybot for windows batch install script needs to create another batch file


This Supybot for windows batch install script needs to create another batch file...

The Problem:

(1) I have a directory that has a file that ends with .conf

(2) There is only one file in this directory that ends with .conf

(3) But I don't know what this file starts with.. all I know is ????????.conf

(4) How do I set the filename.conf and remove the .conf part of the file name?

(5) As it is just the beginning of the filename that I need.

Example:

C:\runbot>find "supybot.ident: " | type *.conf > temp.txt

robotbot.conf

Outputs : robotbot.conf

The quest, is how do I set a variable=robotbot

=========================================================================

The Input was this file named "RootCode.conf" among many others within the directory searched:

RootCode.conf

The Solution is:

FOR /F "tokens=1,2 delims=." %%a in ('FINDSTR /M "supybot.ident:" *.conf') DO SET USER=%%a&set dontneed=%%b

echo %USER%

pause

The Output is:

C:\runbot>FOR /F "tokens=1,2 delims=." %a in ('FINDSTR /M "supybot.ident:" *.con f') DO SET USER=%a & set dontneed=%b

C:\runbot>SET USER=RootCode & set dontneed=conf

C:\runbot>echo RootCode RootCode

C:\runbot>pause Press any key to continue . . .

Winner... Special thanks Everyone


Solution

  • Your example of piping the output to typecommand is either wrong or useless. So I am assuming you mistyped and the real line was piping the other way around, and thus I am assuming that you are trying to find the filename of the file that contains the string "supybot.ident: ". In that case I would suggest to use findstr command instead.

    FOR /F "tokens=*" %%a in ('FINDSTR /M "supybot.ident:" *.conf') DO SET USER=%%a
    

    See HELP FINDSTR, HELP SET and HELP FOR for more information.