- Posts: 455
File path without a filename
- FlowHeater-Team
-
Topic Author
- Offline
- Admin
-
Less
More
18 minutes ago #3846
by FlowHeater-Team
Best wishes
Robert Stark
File path without a filename was created by FlowHeater-Team
Translated post from the German Support Forum. You can find the original post here:
Dateipfad ohne Dateinamen
Hello,
Can I also specify the path on the Read page (on the left) using *.csv? Unfortunately, I'm getting the error message “TextFile Adapter: File [*.csv] not found.”
There is only one .csv file in the directory, which I'd like to use directly. Can I specify a path without having to specify a specific filename?
Hello,
Can I also specify the path on the Read page (on the left) using *.csv? Unfortunately, I'm getting the error message “TextFile Adapter: File [*.csv] not found.”
There is only one .csv file in the directory, which I'd like to use directly. Can I specify a path without having to specify a specific filename?
Best wishes
Robert Stark
Please Log in or Create an account to join the conversation.
- FlowHeater-Team
-
Topic Author
- Offline
- Admin
-
Less
More
- Posts: 455
2 minutes ago #3847
by FlowHeater-Team
Best wishes
Robert Stark
Replied by FlowHeater-Team on topic File path without a filename
Hi Anika,
The TextFile Adapter cannot process wildcards in the Designer configuration. Using the Batch module , it would be possible to run the definition for all CSV files in a directory.
e.g. FHBatch.exe /ReadFileName C:\Temp\*.csv Import.fhd
This command would process all CSV files in the C:\Temp directory using the FlowHeater definition “Import.fhd.”
Workaround) If your input file has different names each time and you want to run it without changing the definition, you can proceed as follows.
Drag a .NET Script Heater onto the designer, paste the C# script below into it, and set the “Run at” option to “Start.”
The script is then called once before execution, searches for a CSV file in the current directory, and replaces the first CSV file found in the TextFile adapter on the READ side.
Please note: Only the first CSV file found will be processed. Of course, the structure of the CSV file must also match the specifications provided originally!
You will find a short example in the attachment.
C# script to process the first CSV file in a directory
The TextFile Adapter cannot process wildcards in the Designer configuration. Using the Batch module , it would be possible to run the definition for all CSV files in a directory.
e.g. FHBatch.exe /ReadFileName C:\Temp\*.csv Import.fhd
This command would process all CSV files in the C:\Temp directory using the FlowHeater definition “Import.fhd.”
Workaround) If your input file has different names each time and you want to run it without changing the definition, you can proceed as follows.
Drag a .NET Script Heater onto the designer, paste the C# script below into it, and set the “Run at” option to “Start.”
The script is then called once before execution, searches for a CSV file in the current directory, and replaces the first CSV file found in the TextFile adapter on the READ side.
Please note: Only the first CSV file found will be processed. Of course, the structure of the CSV file must also match the specifications provided originally!
You will find a short example in the attachment.
C# script to process the first CSV file in a directory
Code:
public object DoWork()
{
// Set the first file found in the TextFile adapter on the READ side
// Note: This file must have the same structure as specified!
TextFileAdapter adapter = (TextFileAdapter)AdapterRead;
string path = Path.GetFullPath(adapter.Filename);
string ext = "*" + Path.GetExtension(path);
path = Path.GetDirectoryName(path);
// Find all files that match the wildcard
string[] files = Directory.GetFiles(path, ext);
if (files.Length < 1)
throw new Exception("No matching file found!");
else if (files.Length > 1)
throw new Exception("More than one matching file was found!");
adapter.Filename = files[0];
// A return value is not required for “Run at Start”
return null;
}
Best wishes
Robert Stark
Please Log in or Create an account to join the conversation.
Time to create page: 0.190 seconds