SSIS 2008 pb with file system task to delete a file - ssis

in my foreach loop container, I would like to delete the current processed file.
I try as follows, but no file is deleted at the end, any idea??
Here is the property of my loop , Current processed file comes from FileNameSimu variable
I would like to delete the current file

Make sure that the value in the variable User::FileNameSimu contains the file path like C:\Folder1\SubFolder2\File.txt and not just the file name File.txt
Please note the description of the property SourceVariable on File System Task. It expects a path.
On the Variables window, select the variable FilePath and press F4 to view the properties of the variable. Change the property EvaluateAsExpression to True and set the value #[User::Directory] + #[User::FileName] to the property Expression assuming that your variable Directory contains the folder path and the variable FileName contains the name. Make sure that the variable Directory ends with a backslash at the end like C:\temp\ and not like C:\temp. If it doesn't have a backslash at the end change your expression to #[User::Directory] + "\\" + #[User::FileName]
Or use the backslash in the expression

Related

Batch File in SSIS

I am producing two files from an SSIS package.
One is the main content and the other is the header.
After I have output both files - I am then merging them using an Execute Process Task.
So I have a content.txt and a header.txt.
/C copy /B \filepath\header.txt + \filepath\content.txt \filepath\result.txt
What I want to do at this stage it append the data to the result.txt so it becomes result_09102019.txt.
How do I achieve that within the snippet of code I have above?
I am not using an Execute Process Task now in order to achieve the filename.
Instead using an Execute SQL Task to simply write the result set to a variable - which I then point at me Flat File Connection.
select 'filename_' + format(getdate(), 'yyyyMMddHHmm') + '.csv'
The single row result set gets written to a variable called OutputFileName.
I then have an OutputFolder variable and then combine the OutputFolder and OutputFileName to another variable called OutputPath.
Output path is then added via an Expression to the file connection.
suggestion - explore the use of variables in building up file names.
Store filename in variable and create tables with the filename in SSIS

SSIS can't create Destination flat file

I have a package where I have an input file that has a header line
TI,2
and detail line(s) that look like this
YP,302,,0000000000000061.00,20170714,CHK #9999,R04,9999
I have to do some processing on the detail lines. The file name is in a variable called User::FileName
In my Data Flow I have a conditional split where I shoot the Header Record to a path where I create a file with just the header record (it doesn't change).
I process all of the detail records. I have to go into SQL to do this and write out the results into a comma delimited flat file with the same name as the input file (using the variable).
So now I have a Header file with a fixed name and a detail file with the name in a variable. I need to combine these. I am trying to create a .BAT that that says
copy /y /d /b header.txt + User::FileName User::Filename (with the proper values substituted for the variable) and then execute this with an Execute Process task.
I am doing this with a Data Flow Task. The source is a Flat file (copy.bat) that contains 2 columns. Column 0 has copy /y /d /b. I have a derived column called Rest_of_Copy that has header.txt + User::FileName + " " + User::Filename
On the output file Destination I also have 2 columns. I am mapping Column 0 (the copy /y /d /b) to column 0 on the output file and The Derived Column Rest_of_Copy (which should contain the results of header.txt + User::FileName + " " + User::Filename). The Connection Manager for the Destination File is Copyout.bat
When I run the package Copyout.bat is empty.
I can't figure out why. Can anybody help?
I found a different way to do it. I wrote out the 2 files to fixed names, so the COPY command was fixed, and then renamed the output file to the SSIS variable using a File System task.
Thanks,
Dick

kdb+ : Command Line parameter as a filename to be saved as

How do I parse a command line parameter and use it as a variable in the script to be used as filename to be saved as. I have tried the below but it is not working
fname:.z.X[2]
.....
...more code...
....
/Save the table into a csv file
`:(fname,".csv") 0:csv 0: table
You need to always remember the left of right evaluation.
In your case you are trying to write the csv delimited table to (fname,".csv"), which is only a string.
Further you want to use `$ to parse to a symbol (not `:), and use hsym to create a file path (prefix with ":")
bash> q script.q filename
q)(hsym `$ .z.x[0],".csv") 0:csv 0: ([]10?10)
`:filename.csv

Passing spool file name to SQL script as a parameter from batch file - unexpected behaviour

When I pass in a name for a spool file, I get an incorrect file name. For example, I double-click command.bat and enter 'TEST' (without quotes) at the prompt and hit enter. Script runs and queries that database properly, but my output file is 'TESTcsv.LST' (again without quotes). If I change the file name to a proper 'TEST.csv', I can see that the output is correct.
command.bat:
#echo off
SET /P name="Enter name: "
sqlplus username/password #script.sql %name%
script.sql:
--A whole bunch of formatting code
...
spool T:\&1.csv
SELECT * FROM tablename WHERE somecol='&1';
spool off
exit
Furthermore, if I change the sqlscript to read:
spool T:\'&1'.csv
My output file becomes 'TEST'.csv. When I leave out the single quotes, why does it delete the '.' in the spool file name and append '.LST'?
Note that the parameter being passed to the script is also being used in the query without any issues.
I've also tried passing the arguments using sqlcmd utility, but no luck there, so I'd like to get this working without sqlcmd if possible. For now, I can rename the file, but it is a bit annoying to have to do that every time I need to run the script.
Found the following that answered my question when searching for another issue. Variable names must be terminated with a '.' to properly concatenate the variable and surrounding string. http://www.orafaq.com/node/515
Now, what if I want to prompt for the user's name, like Fred, and set the prompt to FredPrompt> ? Simply stuffing the variable in there won't do:
MyPrompt> set sqlp '&EnterNamePrompt> '
Enter value for enternameprompt: oops
oops>
And neither will concatenating, since SQL*Plus doesn't accept concatenation for the values passed to its SET commands:
oops> set sqlp '&EnterName' || 'Prompt> '
Enter value for entername: fred
SP2-0158: unknown SET option "||"
fred
The power user tip to remember here is that variable names can be terminated by a period. Simply tuck a period between your variable name and the succeeding text:
SQL> set sqlp '&EnterName.Prompt> '
Enter value for entername: Fred
FredPrompt>

Passing a directory and file name variable that contains spaces from Foreach Loop to an Execute Process task

I have a Foreach File Enumerator that loops through all files in a folder, saving the directory and file name to a variable #NextFile.
Inside the Foreach, I have an Execute Process Task which is passed the variable #NextFile.
I pass the variable by selecting Edit on the Execute Task, Expressions->Arguments->#[User::NextFile].
This works fine if the file name has no spaces, but when there is a space, the String passed in will end where the first space appears.
Eg: if the directory name is c:\files\file a.pdf, the variable will be c:\files\file
I've tried to enclose NextFile in quotes "#[User::NextFile]" but then the variable is set to "#[User::NextFile]"
Make your expression look like:
"\"" + #[User::Filename] + "\""