Click here for important information about

Solved Why does code not work?

March 31, 2012 at 20:06:02
Specs: Windows 7
Why does this not work? It doesn't make sense! It's just refusing to do any code:

@echo off
set tested=0
set name=
set file=Data_file
set cnt=0
if exist "%file%.txt" do (
	for /F "delims=" %%j in (%file%.txt) do (
		set /A cnt+=1
		if %cnt% == 1 (
			set name=%%j
			set /A cnt-=1
		) else set line!cnt!=%%j
	goto start
) else (
	goto new_data
if %tested% == 1 (
	echo.Error: Couldn't create new data.
	pause >nul
	echo.Try again?
if %tested% == 0 (
	echo.No data found.
	pause >nul
	echo.Create new data?
	set tested=1
if %errorlevel% == 1 call :name
if %errorlevel% == 2 (
	echo.Ok. Program will now close.
	pause >nul
goto test_file
echo.What is your name?
set /p name=""
rem Put code in later
pause >nul

The output is usually just the pause then it closes. And no, the data file doesn't exist. And yes, I have tried switching the data file's name (many times).

Also: Thanks ahead of time! I would like help soon (though I can wait)!

See More: Why does code not work?

March 31, 2012 at 20:21:34
✔ Best Answer
I didn't check it all, but this jumps out at me:

if exist "%file%.txt" do (

There shouldn't be a "do" there, that's only for "for" loops:

if exist "%file%.txt" (

Report •

March 31, 2012 at 20:24:20
@Judago Thanks! It's always the stupid errors that cause the most harm :P

Report •
Related Solutions

Ask Question