1.

Solve : Batch Files Not Working Anymore?

Answer»

Hi all,

Everything was working fine last week but when I came back to WORK on monday my bat files stopped working. They didn't stop working completely, but only the really basic codes are working and the more complex code isn't working anymore. Would anyone have any idea what could be causing that?

What happens is this, for example with this bat file:

Code: [Select]@ECHO OFF

CD /d "%~dp0"
CD Batch


:LOOP
FOR /F "tokens=* delims=" %%V IN ('dir *.bat /b 2^>^&1') DO (
IF "%%V"=="File Not Found" GOTO :DONE
call "%%V"
GOTO LOOP


:DONE
ECHO RENDERING COMPLETED!
ECHO YOU MUST NOW SMILE!!
PAUSE

CD /d "%~dp0"
DEL "Exterior Snapshot Rendering.bat"

EXIT
It works until it gets to this line:

Code: [Select]FOR /F "tokens=* delims=" %%V IN ('dir *.bat /b 2^>^&1') DO (
Then it simply closes without giving me any error message. I tried to open the .bat file through a shortcut that keeps it alive and there isn't any error message. It simply acts as if the code was over.

That .bat file used to work great, and I've got some other .bat files also that don't work anymore and that used to work perfectly.


Anyone has any ideas on how to solve this?If this was working and now its not I would look at the permissions that the batch file runs under than check to see if anything else has changed like folder security.

Batch files normally don't stop working. Have you tried to run this on another machine?

One last thing I would check is to see if someone made a change to the batch file. Look at the date/time stamp.

Either there is a typo or a missing close parenthesis prior to the goto loop:

Code: [Select]@ECHO OFF

CD /d "%~dp0"
CD Batch


:LOOP
FOR /F "tokens=* delims=" %%V IN ('dir *.bat /b 2^>^&1') DO (
IF "%%V"=="File Not Found" GOTO :DONE
call "%%V"
)
GOTO LOOP


:DONE
ECHO RENDERING COMPLETED!
ECHO YOU MUST NOW SMILE!!
PAUSE

CD /d "%~dp0"
DEL "Exterior Snapshot Rendering.bat"

EXIT

ECHO YOU MUST NOW SMILE!!

It's not a requirement, the interpreter doesn't care, but indenting for loops and if statements makes for EASIER reading by human types.Hi,

Thanks for your replies. I know it's not a problem in the code because it was working last week. And also it's not the only bat file that doesn't work. I have a couple of bat files where it fails at some parts. And it all started when I got in on monday...

If anyone would know of a solution to fix it let me know. If there isn't any solution, I'll just have to wait, because I supposed to be getting a new computer in a couple of days so I guess that will fix the problem...

Anyways, thanks for trying to help!The easy way to debug a batch file is to comment out the @echo off STATEMENT and watch the file run. It also allows you to see the values the variables take on and the general path the logic follows.

Quote

I'll just have to wait, because I supposed to be getting a new computer in a couple of days so I guess that will fix the problem...

Perhaps, but as was previously mentioned, batch files do not just stop working. Most likely is some environment change occurred that the batch files(s) did not account for.

Good luck.
I tried removing the ECHO OFF in on of the batch files that don't work anymore, and there isn't much to see. It's the same thing as with the ECHO OFF, it stops without telling me why...

Here's all it says (from the code posted in the first post):
Quote
E:\Documents and Settings\username\My Documents\Tool>CD /d "E:
\Documents and Settings\username\My Documents\Tool\"

E:\Documents and Settings\username\My Documents\Tool>CD Batch

E:\Documents and Settings\username\My Documents\Tool\Batch>E:\
Documents and Settings\username\My Documents\Tool\Batch>
If the code you posted is what is actually running, then the FORMAT of the for statement is incorrect. There is an open parenthesis after the DO but it is never closed.

In your earlier thread you were moving the files to an archive. This code appears to be in an endless loop as long as the directory has one batch file.

Posted Code:
Code: [Select]@ECHO OFF

CD /d "%~dp0"
CD Batch


:LOOP
FOR /F "tokens=* delims=" %%V IN ('dir *.bat /b 2^>^&1') DO (
IF "%%V"=="File Not Found" GOTO :DONE
call "%%V"
GOTO LOOP


:DONE
ECHO RENDERING COMPLETED!
ECHO YOU MUST NOW SMILE!!
PAUSE

CD /d "%~dp0"
DEL "Exterior Snapshot Rendering.bat"

EXIT
omg...

That was only it? Thank you so much!

I still don't understand how that could happen since it was working fine last week. Maybe I made some change in the code and removed the ")" by mistake, because it's a .bat file that's created from a JAVASCRIPT so maybe I made a mistake while updating the javascript.

And also I still don't understand why another bat file wasn't working, but it's another one that was created from the javascript and I just tried it again and now it works so... it's kind of weird, but anyways...

The important part is that has it says at the end of my batch file:
I MUST NOW SMILE!!!


Discussion

No Comment Found