|
Answer» I've got the following CODE:
Set /P Input= Selection: For /F %%a in ('dir /B /O /A:D *.*') Do ( Echo %%a Pause )
Right now, it echos the folder name (in alphabetical order), pauses, and REPEATS echoing the next folder name in the list. I want to be able to take the variable (%%a) and find out what the first 4 characters of the folder name so that I can compare it against what the user inputed. From there, I can write the batch file to do what I need from the folder the user selected. Is there a way to do this?
Thanks.There are probably a few ways to do this.
Code: [Select]echo off set /p input= Selection: for /f "TOKENS=* delims=" %%a in ('dir /b /o /a:d ^| findstr /i /b /c:"%input%"') do ( echo %%a )
Good luck.
The compare is set up as case insensitive. Remove the /i switch from the findstr command if necessary.
slice string THUS
%var:~offset_from_start,number_of_characters%
The first character has an offset of zero
so if var=chicken
%var:~0,4%=chic
and
%var~4,3%=KEN
|