|
Answer» Hello everybody,
I am working on a batch file which should load files into an ORACLE database. Now, the overall idea is: I have a folder in directory Dir1 in which the files are going to be stored periodically. :: I am trying this way for loading these files into the DB: :: At first I’m making use of this portion of code to get the file_Name of the last created file in Dir1, and :: to write it as a single line in another file lastFileName.txt, and finally moving the lastFileName.txt to another directory Dir2
************************************************ @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_file move lastFileName.txt C:\Dir2 ************************************************
:: Than, I use this second portion of code, in order to get the content of lastFileName.txt, assign it to a variable (var_path_temp) :: and use this variable THROUGHOUT the rest of this portion of code, in order to create some other files (Control.ctl and log_File.log in Dir3). :: Finally, I load the file (retrieved from lastFileName.txt) and remove this (just loaded) file to another location Dir4
************************************************ 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) pause goto :move_file2 ) :move_file2 move Control.ctl C:\Dir3 sqlldr username/[emailprotected] control=C:\Dir3\Control.ctl log=C:\Dir3\% var_path %.log.log data=%var_path_temp% goto :move_proc_files ) :move_proc_files for /f "tokens=1 delims= " %%c in (C:\Dir2\lastFileName.txt) do ( move %%c C:\Dir4 ) ************************************************
Thnx in advance, PupliThnx everybody,
It seems that I just resolved my problem. I had an extra "(" in my code, and I also removed to of my GOTO statements as they preventet the loop to be executed properly.
By the way, I would have needed some help regarding some error checking issues. I am now working on stating some error checking conditions depending on whether the files have been loaded successfully or not. How can I achieve this using .bat syntax
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 THEN BREAK; > error_log.log echo Could not create file Control.ctl; EXIT; ELSE IF NOT Exists xxx.log THEN BREAK; > error_log.log echo Could not create file xxx.log; EXIT; ELSE Continue with execution ******************************************************************
Hi again,
Well, it seems that I'm after it
I've arived in this part Code: [Select]if not exist Control.ctl ( > error_log.log echo Could not create file Control.ctl exit ) if not exist xxx.log ( > error_log.log echo Could not create file xxx.log exit ) ... HEREINAFTER STATEMENTS TO CONTINUE EXECUTION ...
but I do not understand, what is wrong
|