Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Name: pball
I have this batch script which does something which shouldn't be important. I want to check if a file was drug into the window and thus was selected.
It works when no file is entered, but when a file is entered it gives the error "or was unexpected at this time." which has me puzzeled.
@echo offsetlocal enabledelayedexpansion
echo drag and drop sfv onto window
set /p settings=
clsif "%settings%" == "" goto fail
for /f "usebackq tokens=*" %%x in (%settings%) do (
call :check %%x
if /I not "!z:~0,8!" == "!z:~14,22!" echo %%x
set z=
)goto end
:check
set x= %1 %2
:againif "%x:~-1%" == "[" set s=%z% & goto :EOF
set z=%x:~-1%%z%
set x=%x:~0,-1%
goto again
:fail
echo no file selected:end
pause

[Edit]
Try the "if not defined settings goto fail" bit first, especially if you file will always contain "["
[/Edit]
I suspect your problems are coming from trying to use variables that are undefined. Try adding this line just below the :again label.
if not defined x goto :eof
I can also see another problem as well, the first time you call check %z% is also undefined, so if the last character of %x% was "[" %s% would be set to nothing. It may be a good idea to promote the line "set z=%x:~-1%%z%" above the line above it, making any other adjustments necessary, to ensure it can deal with the possibility.You could also use "if not defined settings goto fail" instead of "if "%settings%" == "" goto fail"
Without knowing more about your text file's contents and your objective I'm not sure if this will fix the problem or not.

![]() |
Batch file check files sp...
|
Regex / Pattern Matching ...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |