I want to process all the .CSV in files (data files) in specific folder. My problem is how can i pass this file name to sql loader as every time it would be different file name.
I want to have all this stuff in single batch file so that i can schedule it whenever i wish.
Can anyone help me out pls?
Thanks in advance....
Mehul
Assuming for each .csv file there is a corresponding .ctl (control file) the following should work:
for %%i in (*.csv) do (
sqlldr data=%%i control=%%~ni.ctl log=%%~ni.log
)
This assumes the files are in the current directory. You might want to add the approriate cd commands before iterating over the input files.
Related
I have a CMD script that currently copies file from one location to another. It overwrites the old file with that name in the destination source which is fine. Now, I would like to keep historic data available in the Archive (separate csvs with different names). I am trying to copy the existing file to the archive before the file is updated with new data. What I thought is to create Archive folder and copy original file to it. However, with the setup I have now, it will be erasing the older version of the file because they would get the same name applied.
I tried adding DAT variable which is a current date and append this in the beginning of the file name but it prompted a syntax error. Not sure if this is even possible in CMD. I would really appreciate some assistance. If you take DAT out of the code, it will work and copy the file fine but the next time I run this script, it will overwrite the file while I want to have different historic files with name containing a date with identifier. If appending date is not possible, perhaps we could create version number by ourselves starting from 1.
Here is the code that I tried:
#ECHO OFF
set day=%date:~0,2%
set month=%date:~3,2%
set year=%date:~6%
SET DAT=%DATE:~6%%DATE:~3,2%
Set ZEIT=%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%
copy /Y \\srvditz1\DataXchange_R3\TUS_EXCHANGE\TUS300_digi_SFM\30_Visualization\ZPP00138_TUS350.csv \\srvditz1\DataXchange_R3\TUS_EXCHANGE\TUS300_digi_SFM\30_Visualization\Archive\%DAT%_ZPP00138_TUS350.csv
This line adds an extra blank at the end of the line which causes your trouble.
SET DAT=%DATE:~6%%DATE:~3,2%
copy /Y \\srvditz1\DataXchange_R3\TUS_EXCHANGE\TUS300_digi_SFM\30_Visualization\ZPP00138_TUS350.csv \\srvditz1\DataXchange_R3\TUS_EXCHANGE\TUS300_digi_SFM\30_Visualization\Archive\%DATE:~6%%DATE:~3,2%%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%_ZPP00138_TUS350.csv
If you put directly without any variable this works.
I am working on a batch file and trying to write the correct windows commands.
1) Command-line from Windows
2) Use commands to scan the zip file so that it will look inside of the zip file for a specific string in the file within the zip file.
3) If the scan finds that specific string in the file that is within the zip file then move that zip file to another specified directory.
Is it possible using dos commands within a batch file?
I want to learn more on this. Anyone have any guidance or suggestions?
I have a question copy files with batch at windows machine.
For example, I have a file named ja.html and duplicate the file to many files with certain file names following:
en.html
zh-ch.html,
ko.html,
id.html
in same directory.
Thanks in advance.
I have two folders in the same drive. I want to create backup of an access database. I need to copy the main file, append the name with the date and time and store it in a different folder.
Source Folder: G:\PMO\Talent Mgt\Data
Source file: Talent_Management_Data.accdb
Destination File: G:\PMO\Talent Mgt\Archive\Talent_Management_Data.accdb_20120101
Any suggestions?
You can achieve this by using for command to execute copy for each file. A simple batch file would be:
cd "G:\PMO\Talent Mgt\Data"
for %%A in (*.accdb) do copy %%A ..\Archive\%%A_%date:-=%
I used the follwoing statement to copy over files from one folder to another... but it does not copy over the subdirectory (and the files and folders under that subdirectory)
%sysExec copy "&driv.\&path1\*" "&driv.\&path2";
Any Solutions?
I don't think this is a SAS question. This would depend on your enviroment.
If you are on Windows, try xcopy
If you working in another environment, post additional info
I usually use a FILENAME PIPE for this, and then execute through a data step. The standard output is then captured in the data step. I've not got SAS available at the moment, but it would look something like this:
filename mycopy pipe """xcopy "&driv.\&path1\*.*" "&driv.\&path2\""";
data copydir;
infile mycopy;
input;
stdout=_infile_;
run;
You can check the data set's STDOUT variable for feedback on what happened.
If you're still running into trouble, then test the command you're running from the command line first and then transfer to your SAS code.
Try this . . .
%sysExec xcopy "&driv.\&path1\*.*" "&driv.\&path2\*.*" /s;
The /s option copies all subdirectories - provided they are not empty.