Batch Script not working

February 7, 2010 at 23:42:52
Specs: Windows XP, Core2Duo/2GB
Hello everybody,

Plese guys help me!
I am working on a batch script but I am not understanding why this doesn't work.

@echo off & setLocal EnableDELAYedeXpansion
pushd C:\Dir1
for /f "tokens=* delims= " %%b in ('dir/b/a-d/o-d/tc') do (
> lastFileName.txt echo 'C:\Dir1\%%b
goto :move_file
move lastFileName.txt C:\Dir2
for /f "tokens=1 delims= " %%a in (C:\Dir2\lastFileName.txt) do ( set var_path_temp=%%a
set var_path=!var_path_temp:~-20!
> Control.ctl echo load data infile %var_path_temp%' append into table TBL_NAME fields terminated by "," optionally enclosed by '"' (Field1, Field2, Field3)
goto :move_file2
move Control.ctl C:\Dir3
sqlldr user/pass@path control=C:\Dir3\Control.ctl log=C:\Dir3\% var_path %.log.log data=%var_path_temp%
goto :move_proc_files
for /f "tokens=1 delims= " %%c in (C:\Dir2\lastFileName.txt) do (
move %%c C:\Dir4

I am in desperate need of help and advices!!!

See More: Batch Script not working

Report •

February 7, 2010 at 23:47:52
Oops - script didn't show when the post was opened. Ignore please

Report •

February 7, 2010 at 23:58:21
I do not understand why I can not assign the value to variable var_path_temp. The file Control.ctl is supposed to be generated with the value previously stored in var_path_temp, but I actually find a blank space.

Report •

February 8, 2010 at 02:43:53
Hi again,

I was thinking about dividing the above code into several separated batch files, and build another one which should call
the snippets one after the other.

Do you think this would have worked?

As you can see from the above "main" code, I have made no use of any error checker, because I have not tested it yet, since it is un-usable, ... consequently I wonder if using the "splitting" method, will allow me to make use probable error handler.

Report •

Related Solutions

February 8, 2010 at 03:37:51

When you enable the Delayed Expansion it is better you mark the environment variables by the ! symbol instead %. To explain in depth this issue is far beyond this short note, so replace

> Control.ctl echo load data infile %var_path_temp%' append into table


> Control.ctl echo load data infile !var_path_temp!' append into table

More it seems there are left and right "(" ")" unpaired, but that may be or may be not as your code is cumbersome and confused for my way.

Pay attention you can't code goto statements that refer to labels inside For loops as the flow of processing is broken.

Report •

February 8, 2010 at 05:01:20
Ciao IVO,

It seems that you are quite right!
Thanks to you I could resolve the problem, as it seems to be more ')' than needed, and of course, I removed the GOTO statements.

By the way,
I am now working on stating some error checking conditions depending on whether the files have been loaded successfully or not.

The first condition that this batch script has to follow, is based on the Control.ctl file (and therefore the .log file)
In an algorithmic way, it would have been:

IF NOT Exists Control.ctl
> error_log.log echo Could not create file Control.ctl;
IF NOT Exists xxx.log
> error_log.log echo Could not create file xxx.log;
ELSE Continue with execution

Report •

February 8, 2010 at 05:03:48
Some time ago I had a similar problem, seems that the FOR /F loop does not really like the GOTO command ...

Report •

February 8, 2010 at 05:50:28
I am not sure if you want a tip for coding what you posted as pseudo-code, anyway...

if not exist Control.ctl (
  > error_log.log echo Could not create file Control.ctl
if not exist xxx.log (
  > error_log.log echo Could not create file xxx.log

Report •

February 8, 2010 at 06:39:59
Actually I wanted my "pseudo-code" translated into a valid batchScript code.

Let me ask you 2 more other questions:
1. Should I specify the directory of Control.ctl and xxx.log,/b> ???

2. What difference will made if I replace exit with eof


Report •

February 8, 2010 at 12:33:41
Answer to question #1

You have always to specify the directory of referenced files if they do not belong to your current/working directory.

Answer to question #2

EXIT closes the console window the batch scripts executes inside while GOTO :EOF just terminates the script with no direct action on the window.

If the window was opened by issuing the CMD.EXE command then the console window remains open displayng the prompt.
The same can be achieved by EXIT /B.

If the batch was launched via a shortcut the window persists grayed and inactive and must be cleared manually by clicking the X on the right upper corner.

By the way, are you Italian or do you know I'm Italian (you welcome me by saying Ciao)?

Report •

February 9, 2010 at 00:45:51
Ciao IVO,

Innanzitutto ti voglio ringraziare per tutte le tue risposte.

Infatti ho letto qualcuno dei tuoi articoli, e mi sono reso conto che il modo in cui salutavi, era italiano :))
No! Nn sono Italiano,...Con Italia mi lega solo il passato di mio padre, (anzi del mio bis bis bis nonno) :)))

Mile grazie ancora,
(Taulant(JANI) Piero)

Report •

February 9, 2010 at 02:40:52
Ciao Piero,

grazie per la tua risposta e il tuo ottimo Italiano.

E' raro e sorprendente trovare un discendente di Italiani all'estero con una padronanza così disinvolta di una lingua ormai ridotta a dialetto nel mondo globalizzato. Il mio Inglese è assai rudimentale, ma sufficiente per leggre e scrivere rapporti tecnici che sono obbligatoriamente in Inglese.

Grazie ancora e sempre pronto a dare una mano, anche via e-mail con messaggi privati..

Gales/guys accessing this post, I apolologize for the above section in Italian; that was a nice exchange of "twitters" with a friend mastering my mother tongue language. No technical info at all.

No fear, the official language is English and that will be.

Ivo Luigi Bertani - Milano (Italy)

Report •

Ask Question