Creating a filename field to later write to file - pentaho

I have a transformation with the following fields:
foldername: foo
filebasename: bar
texttostore: foobarfoobarfoobar
I want to create a file in a folder named foo which is located at the same folder than the Kettle script. The filename must be called bar.txt.
I see that the step Text file output can get the filename from a field.
How can I create a filename that refers to file ./foo/bar.txt?

In the Text File Output step you can select Accept file name from field? and specifiy a field, eg. filename, in the incoming rows that contain the filename (including path, but excluding extension). You can construct this filename in a previous step, for example with a Formula step that constructs the filename from the formula "./" & [foldername] & "/" & [filebasename].
Furthermore you can use internal variables, accessed via ${} to refern to certain paths relating to the transformation, for example ${Internal.Transformation.Filename.Directory}.

Related

How to indicate a directory path using variables?

I have to implement the use of a certain .exe file in VBA. The .exe takes as input a specific type of file and outputs a .txt file.
When I write the whole directory of both the input and output files, the code works. When I split the directory and store the parts in variables, it doesn't.
I need to split it because I am going to use this .exe with different directories so the user could choose the wanted directory.
Sub convert()
Dim directory As String
Dim Filename As String
directory = "C:\Users\user1\Desktop\reporting\201703161224"
Filename = "\input.set"
Shell "cmd /c""C:\Users\user1\Desktop\reporting\appli.exe
C:\Users\user1\Desktop\reporting\201703161224\input.set>
C:\Users\user1\Desktop\reporting\201703161224\output.txt"
'this works well
file = directory & Filename
Shell "cmd /c""C:\Users\user1\Desktop\reporting\appli.exe file>
C:\Users\user1\Desktop\reporting\201703161224\output.txt"
'this doesn't work
End Sub
You need to break out of the quotes and Concatenate to use your file string variable
Shell = "Hard_Coded_String_1" & file & "Hard_Coded_String_2"

VBA store path including Environ("username") in a text file

I am trying to create a text file that stores a folder path. This text file is then referenced via a vba sub. The path I want to use is something like:
"C:\Users\" & Environ("username") & "\AppData\Roaming\Microsoft\Templates"
This works fine in the sub but I've tried all kinds of variations in the text file but none of them get recognised and trigger error 52 - bad file.
Is there a way to make this work? I'm trying to allow people to set a different file path without needing to modify the code.
If you are trying to provide a path to the folder where user templates are stored then you could try
ActiveDocument.AttachedTemplate.Path
as an alternative (returns the path to the folder where the current template is stored for the user).
Otherwise store the path template as something like
"C:\Users\###UserName###\AppData\Roaming\Microsoft\Templates"
Which gives you a single string to retrieve. Then you can use the VBA Replace function to change the ###UserName### to the value of Environ("UserName)"
my_user_path = replace(my_path_template, Environ$("UserName"))
You might also want to explore using either a CustomDocumentProperty, or a Variables, to store your path template as this keeps the path template string as part of the Document or Template and not in a separate file.

VB.net FileSystem.rename - old path knowing only a substring

How can I rename a file that I don't know the full name, but I only know that it begin with a base string?
I must rename a file in a folder, that begins with a default string and then has extra unknow chars. I'm sure in that folder will be only one file beginning with that string.
It would be something like searching "string*.txt" and rename it with "string.txt", but FileSystem.rename doesn't accept oldPath with "*" as argument.
Dim _files as String() = IO.Directory.GetFiles("c:\temp\", "string*.txt")
IO.File.Move(_files(0), "c:\temp\newfilename.txt")
Still needs some checking if file found, etc. but this should work
You need to loop through all the files in your given directory, if one name matches then you know it's your file.
Structure of the code might look like this :
Function LookForName(Path As String) As String
'For Each File in your path
'If the name starts with "string" and ends with ".txt"
'You can return this filename
End Function
'You call LookForName with a given path
'You rename the returned file

Zip multiple files to one folder

So I am having trouble trying to reconcile this concept as every change I do doesn't seem to fix the issue.
I have multiline textbox and can enter multiple values separated by commas and here are the details:
Each value represents a folder
And each folder has multiple documents/other folders inside
All of these values are in one main directory (lets call it folder path)
For example say I enter in my textbox "65635,65636" each of those represent a folder in the directory i.e. "\folderpath\65635" and "\folderpath\65636", I am trying to zip these whole folders via DotNetZiplib, I know how to do this if I specifically reference one folder but is there anywhere to loop through the textbox to get the names of the folders and have the files added to one zipped folder?
Using zip As New ZipFile = new ZipFile
Dim files() As String = Directory.GetFiles(folderpath & textboxvalue)
For each textboxvalue in directory.getfiles
zip.Addfile(textboxvalue)
The zipfile function I have would know to loop through these as opposed to assuming it's one big file.
You must split textbox values in array first to get numbers separated by comma. Next you will need Combine your folder with this splited text values, creating path correctly.
Check if folder exists in system if Yes then get all files from Directory and for each filename zip it.
Something like this:
Using zip As New ZipFile("your zip filename")
For Each str As String In textboxvalue.Split(",")
Dim path as String = System.IO.Path.Combine(folderpath, str)
If System.IO.Directory.Exists(path) = False Then
Continue For
End If
Dim files() As String = Directory.GetFiles(path)
For Each fileName As String In files
zip.Addfile(fileName)
Next
Next
End Using

finding file names which consist its name as variable

i am using visual studio 2010
i need a expression to find a file name for eg *.xml is used for finding file name "test.xml" so what will be the expression to find a file name 4374573.xml
i have tried
File.ReadAllLines(TextBox1.Text & "*.xml") but it is only applicable for characters anything for variables.
any help will be appreciable
If you are looking how to find files on disk, you can use the GetFiles method as in how-to-use-directory-getfiles. For more details check:MSDN-GetFiles.
Not sure if this is what you are looking for
Dim path as String = "C:\YourFolder"
Dim fileCollection = My.Computer.FileSystem.GetFiles(path, FileIO.SearchOption.SearchTopLevelOnly, "*.XML")
It will search for every .XML file at the specified path and returns the file list in fileCollection